This one had been biting me on the hiney for some time, so I thought I'd share what I went with.
If you do a "hide()" in the ctor, and then yer main looks like:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
what you have done is told it to hide(), and then show(). That won't work. I made a public variable in my subclassed QMainWindow, so that I do something similar to:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
if (w.bRunHidden)
w.hide();
else
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
if (w.bRunHidden)
w.hide();
else
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
It also doesn't run right without the hide(). I do realize that this doesn't address your problem of showing the other form. If the parent is not visible, neither will the child be. Thus, you would have to make a parentless form, which makes sense on Windows, in any event. It will create its own taskbar entry. You will have to keep up with it's hiding and showing, however. If a user makes the MainWindow visible, and then minimizes it, your child form may need to be hidden too; and restore when the parent is restored. Depending on what you are doing, you might be taking the wrong approach. I made a serial number screen for a prog I'm working on; and simply created it, showed it and dealt with the response in the main, before I ever created the MainWindow. Also, I suppose making that a function is better form.
Bookmarks