Results 1 to 5 of 5

Thread: New to QT, problem displaying main window...

  1. #1
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face New to QT, problem displaying main window...

    Hi Folks!

    Hopefully someone can help me with this newbie problem...

    I am fairly new to Qt, and I have been using MiniGW, QDevelop, Qt Designer and Qt 4.3 under WindowsXP to try and build a "Playground" applciation that I can add things to while I learn Qt. I haven't really used Qt before, but I have used various C++ API's, most notibly the BeAPI from BeOS and Haiku. I also haven't programmed for a few years, so I am a little unsure if my problem is not knowing how to use Qt, or me forgetting how to program C++ period

    I expect my application to show a QMainWindow that will stay on the screen until I press the [x] button, at this point it will close. What I am getting is a Window that flashes on the screen and closes straight away, leaving a process in the Windows process list (I think this is because I am not deleting my new in the relevent destructor)

    I have 3 source files, 3 header files and a .UI file. The .UI file contains a Window with a QMainWIndow object called PlaygroundWindowGUI. If needed, I can send a zip file of my folder to anyone that would like to help.

    Playground.h:

    #ifndef __MAIN_H__
    #define __MAIN_H__

    // place your code here

    #endif // __MAIN_H__

    Playground.cpp:

    #include <stdio.h>
    #include "Playground.h"
    #include "PlaygroundApplication.h"

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

    printf ("Entering main...\n");
    PlaygroundApplication Playground(argc, argv);

    return Playground.exec();

    }// Main

    PlaygroundApplication.h:

    #ifndef __PLAYGROUNDAPPLICATION_H__
    #define __PLAYGROUNDAPPLICATION_H__

    #include <QApplication>

    class PlaygroundApplication : public QApplication
    {
    public:
    PlaygroundApplication(int argc, char *argv[]);

    };

    #endif // __PLAYGROUNDAPPLICATION_H__

    PlaygroundApplication.cpp:

    #include "PlaygroundApplication.h"
    #include "PlaygroundWindow.h"

    PlaygroundApplication::PlaygroundApplication(int argc, char *argv[]):QApplication(argc, argv)
    {

    PlaygroundWindow thisPlaygroundWindow;
    thisPlaygroundWindow.connect( &thisPlaygroundWindow, SIGNAL( lastWindowClosed() ), &thisPlaygroundWindow, SLOT( quit() ) );
    thisPlaygroundWindow.show();

    }

    PlaygroundWindow.h:

    #ifndef __PLAYGROUNDWINDOW_H__
    #define __PLAYGROUNDWINDOW_H__

    #include "ui_playgroundwindowgui.h"

    class PlaygroundWindow : public QMainWindow, public Ui::PlaygroundWindowGUI
    {
    Q_OBJECT
    public:
    PlaygroundWindow( QWidget * parent = 0, Qt::WFlags f = 0 );
    private slots:
    };

    #endif // __PLAYGROUNDWINDOW_H__

    PlaygroundWindow.cpp:

    #include "PlaygroundWindow.h"

    PlaygroundWindow::PlaygroundWindow( QWidget * parent, Qt::WFlags f)
    : QMainWindow(parent, f)
    {
    setupUi(this);

    }

    Can someone please help me work out why this isn't displaying like I expect?

    Thanks,

    Andrew McCall.

  2. #2
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: New to QT, problem displaying main window...

    Qt Code:
    1. PlaygroundWindow thisPlaygroundWindow;
    2. thisPlaygroundWindow.connect( &thisPlaygroundWindow, SIGNAL( lastWindowClosed() ), &thisPlaygroundWindow, SLOT( quit() ) );
    3. thisPlaygroundWindow.show();
    To copy to clipboard, switch view to plain text mode 

    You create the MainWindow on the stack! It will be closed when the PlaygroundApplication constructor ends. Create your MainWindow with new or do it in the main()-function on the stack.

  3. #3
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: New to QT, problem displaying main window...

    Thanks for the quick reply!

    I have move the creation of the window from the stack, but its still not working. One thing I have noticed is that the printf isn't showing any output either, which I am 99.999% sure should be showing!

    Thanks,

    Andrew McCall

  4. #4
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: New to QT, problem displaying main window...

    You may take this as example

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. wnd.show();
    6. app.setActiveWindow(&wnd);
    7.  
    8. int ret = app.exec();
    9.  
    10. // cleanup whatever
    11.  
    12. return ret;
    13. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Wink Re: New to QT, problem displaying main window...

    I think its QDevelop thats causing problems.

    If I use qmake -project, qmake, make from the command line my application works.

Similar Threads

  1. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  2. Replies: 5
    Last Post: 4th August 2006, 23:44
  3. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35
  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.