Results 1 to 8 of 8

Thread: Please instantiate the QApplication object first

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Please instantiate the QApplication object first

    Now my application is finish (only some little modification) and I run in windows mode and works ok. I use Qt because i want to run in windows and linux mode. But when i run in linux mode, compiled and linked ok but run bad. I have this message in linux terminal windows:

    QCoreApplication::applicationDirPath: Please instantiate the QApplication object first

    My main.cpp is:

    Qt Code:
    1. Q_INIT_RESOURCE(qtdam);
    2.  
    3. QApplication *app = new QApplication(argc, argv);
    4. QString path=app->applicationDirPath();
    5. lang.setfile_idioma(path+"/languages.lng");
    6. if (lang.idioma_seleccionado=="Español")
    7. splash->setPixmap(QPixmap(":/images/splash_espagnol.png"));
    8. else
    9. splash->setPixmap(QPixmap(":/images/splash.png"));
    10. splash->show();
    11. Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    12. splash->showMessage(lang.leer_idioma("1"),topRight, Qt::white);
    13. MainWindow mainWin;
    14. mainWin.show();
    15. splash->finish(&mainWin);
    16. delete splash;
    17. return app->exec();
    To copy to clipboard, switch view to plain text mode 

    the splash screen (*.png) works and read the language.lng ok because it puts the correct png, but it stop there. I have to do Ctrl+C to stop the application.

    What's happend???

    PS: I have Mandriva 2007

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Please instantiate the QApplication object first

    Do you instantiate any QObjects, like some static objects before the QApplication?

  3. #3
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Please instantiate the QApplication object first

    Qt Code:
    1. #include <QSplashScreen>
    2. #include <QApplication>
    3.  
    4. #include "mainwindow.h"
    5. #include "languages.h"
    6.  
    7. IDIOMA lang; //-> this is a class
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. Q_INIT_RESOURCE(qtdam);
    12. ...........
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Please instantiate the QApplication object first

    What is the class declaration?
    If it contains any QObjects, then that's your error.

    You define lang as file static, so it will get instantiated before everything you define in main.

    With Qt, no QObject can be instantiated before QApplication. QApplication sets up the proper environment.

  5. #5
    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: Please instantiate the QApplication object first

    What does IDIOMA constructor do? Do you have other global/static objects?
    J-P Nurmi

  6. #6
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Please instantiate the QApplication object first

    I have changed my main.cpp code for this one:

    Qt Code:
    1. #include <QSplashScreen>
    2. #include <QApplication>
    3.  
    4. #include "mainwindow.h"
    5. #include "languages.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. Q_INIT_RESOURCE(qtdam);
    10.  
    11. QApplication app(argc, argv);
    12. QString path=app.applicationDirPath();
    13. IDIOMA *lang = new IDIOMA();
    14. lang->setfile_idioma(path+"/languages.lng");
    15. if (lang->idioma_seleccionado=="Español")
    16. splash->setPixmap(QPixmap(":/images/splash_espagnol.png"));
    17. else
    18. splash->setPixmap(QPixmap(":/images/splash.png"));
    19. splash->show();
    20. Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    21. splash->showMessage(lang->leer_idioma("1"),topRight, Qt::white);
    22. MainWindow mainWin;
    23. mainWin.show();
    24. splash->finish(&mainWin);
    25. delete splash;
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    and in windows works but in linux show the splash screen and dont say nothing, but the app not show????

  7. #7
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Please instantiate the QApplication object first

    Nobody knows what to do???

  8. #8
    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: Please instantiate the QApplication object first

    To me it looks like it shouldn't even show a splash screen at all because you delete it before the application enters to the event loop. Please re-check QSplashScreen docs for how to use it correctly. Notice the example in detailed description.
    J-P Nurmi

Similar Threads

  1. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 12:06
  2. Reponsabilities of QApplication and QMainWindow classes
    By yellowmat in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2006, 16:21

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
  •  
Qt is a trademark of The Qt Company.