PDA

View Full Version : Getting main window to run.



Doug Broadwell
11th October 2006, 02:13
I have created a Main Window app in Designer and run qmake to get the ui_n1.h file created. I have subclassed my Main Window object to place my functionality in it. My n1.h file is:


class MainWindow : public QMainWindow, public Ui::MainWindow {

Q_OBJECT

public:

MainWindow();
};

My MainWindow.cpp file is:


#include <QtGui>
#include "n1.h"

MainWindow::MainWindow() : QMainWindow() {

setupUi(this);
}

My main.cpp is:


#include <QApplication>
#include "n1.h"

int main(int argc, char *argv[]) {

QApplication app(argc, argv);
MainWindow *mainwindow = new MainWindow;
mainwindow->show();
return app.exec();
}

Does this seem right? When I run it nothing happens (or it opens and immediatly closes??).

Thanks

Update! Added code tags.

high_flyer
12th October 2006, 22:05
add app.setMainWidget(MainWindow);

Doug Broadwell
13th October 2006, 03:21
When I add "app.setMainWidget(MainWindow)" I get the error:

QApplication has no member named 'setMainWidget'

???

jpn
13th October 2006, 06:38
There's been a confusion. The method mentioned by high_flyer is for Qt 3. I think the problem must be somehow in the designer .ui file, as I can't see anything in the code you've pasted that could cause the problem. Although the recommendation is to inherit the Ui class privately to ensure ui objects being private in your class, inheriting it as public shouldn't cause any problem like this. Is the designer form really a main window for sure?

high_flyer
13th October 2006, 08:43
QApplication has no member named 'setMainWidget'.
sorry about that - the Qt3 habbits still come out as reflexes some times.... :-)
As jpn said, I could not find a reason why this should not work, and then it just popped up that QAppliaction didn't get the main widget set (and I forgot it was Qt4)...

Are you sure you are using the Qt4 designer and not the Qt3 one?
Such a case should however generate a worning or an error during compile time I think.

Doug Broadwell
17th October 2006, 23:56
I found that my problem was: concurrent with my subclassing my MainWindow I had updated from Qt 4.1.1 to Qt 4.2.0. Now it turns out I cannot make even the simplest test forms made in Designer run - it compiles with no error but running it does nothing. Running the code I submitted in 4.1.1 works just fine.

Anyone know what's changed in Qt 4.2 ?

Thanks