Results 1 to 6 of 6

Thread: Getting main window to run.

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Getting main window to run.

    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:

    Qt Code:
    1. class MainWindow : public QMainWindow, public Ui::MainWindow {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. MainWindow();
    8. };
    To copy to clipboard, switch view to plain text mode 

    My MainWindow.cpp file is:

    Qt Code:
    1. #include <QtGui>
    2. #include "n1.h"
    3.  
    4. MainWindow::MainWindow() : QMainWindow() {
    5.  
    6. setupUi(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    My main.cpp is:

    Qt Code:
    1. #include <QApplication>
    2. #include "n1.h"
    3.  
    4. int main(int argc, char *argv[]) {
    5.  
    6. QApplication app(argc, argv);
    7. MainWindow *mainwindow = new MainWindow;
    8. mainwindow->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks

    Update! Added code tags.
    Last edited by e8johan; 11th October 2006 at 08:16.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting main window to run.

    add app.setMainWidget(MainWindow);

  3. #3
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting main window to run.

    When I add "app.setMainWidget(MainWindow)" I get the error:

    QApplication has no member named 'setMainWidget'

    ???

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Getting main window to run.

    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?
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting main window to run.

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting main window to run.

    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

Similar Threads

  1. Replies: 5
    Last Post: 4th August 2006, 23:44
  2. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35
  3. How to capture exit slot of main window
    By jyoti kumar in forum Newbie
    Replies: 2
    Last Post: 31st May 2006, 07:06
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.