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:
Code:
Q_INIT_RESOURCE(qtdam);
QString path
=app
->applicationDirPath
();
lang.setfile_idioma(path+"/languages.lng");
if (lang.idioma_seleccionado=="Español")
splash
->setPixmap
(QPixmap(":/images/splash_espagnol.png"));
else
splash
->setPixmap
(QPixmap(":/images/splash.png"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(lang.leer_idioma("1"),topRight, Qt::white);
MainWindow mainWin;
mainWin.show();
splash->finish(&mainWin);
delete splash;
return app->exec();
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
Re: Please instantiate the QApplication object first
Do you instantiate any QObjects, like some static objects before the QApplication?
Re: Please instantiate the QApplication object first
Code:
#include <QSplashScreen>
#include <QApplication>
#include "mainwindow.h"
#include "languages.h"
IDIOMA lang; //-> this is a class
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(qtdam);
...........
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.
Re: Please instantiate the QApplication object first
What does IDIOMA constructor do? Do you have other global/static objects?
Re: Please instantiate the QApplication object first
I have changed my main.cpp code for this one:
Code:
#include <QSplashScreen>
#include <QApplication>
#include "mainwindow.h"
#include "languages.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(qtdam);
QString path
=app.
applicationDirPath();
IDIOMA *lang = new IDIOMA();
lang->setfile_idioma(path+"/languages.lng");
if (lang->idioma_seleccionado=="Español")
splash
->setPixmap
(QPixmap(":/images/splash_espagnol.png"));
else
splash
->setPixmap
(QPixmap(":/images/splash.png"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(lang->leer_idioma("1"),topRight, Qt::white);
MainWindow mainWin;
mainWin.show();
splash->finish(&mainWin);
delete splash;
return app.exec();
}
and in windows works but in linux show the splash screen and dont say nothing, but the app not show????
Re: Please instantiate the QApplication object first
Nobody knows what to do???:confused:
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.