Get the instance of QApplication or QCoreApplication inside dll qt 4.8
-
I have my QApplication created inside main() in QthreadTest project. From this project i have called the function inside library felix2.lib which is dynamically build.
Inside felix2 , i need to have QApplication or QCoreApplication to connect to ODBC drivers. i tried using
QCoreApplication *app1 = QApplication::instance(); which is returning NULL.QthreadTest:
main.cpp:
int main(int argc, char *argv[])
{
int i =0;
QApplication a(argc, argv);
QthreadTest w;
w.show();
return a.exec();
}Qthreadtest.cpp
void QthreadTest::startProgress()
{
analyze("Prompted");// function inside lib
}Please help me with how to get the instance of Qapplication that is already defined in main.cpp inside the lib
-
I have my QApplication created inside main() in QthreadTest project. From this project i have called the function inside library felix2.lib which is dynamically build.
Inside felix2 , i need to have QApplication or QCoreApplication to connect to ODBC drivers. i tried using
QCoreApplication *app1 = QApplication::instance(); which is returning NULL.QthreadTest:
main.cpp:
int main(int argc, char *argv[])
{
int i =0;
QApplication a(argc, argv);
QthreadTest w;
w.show();
return a.exec();
}Qthreadtest.cpp
void QthreadTest::startProgress()
{
analyze("Prompted");// function inside lib
}Please help me with how to get the instance of Qapplication that is already defined in main.cpp inside the lib
@meganathan https://doc.qt.io/qt-5/qapplication.html#qApp is your friend
-
i tried like this
QCoreApplication *app1 = qApp->instance(); inside the library but the app1 is NULL , is there any other methods to get the instance. -
i tried like this
QCoreApplication *app1 = qApp->instance(); inside the library but the app1 is NULL , is there any other methods to get the instance.@meganathan Why do you call instance on it?
If you read documentation you will notice that qApp already gives you pointer to QApplication instance. -
@meganathan Why do you call instance on it?
If you read documentation you will notice that qApp already gives you pointer to QApplication instance.@jsulm i used that to confirm whether qApp holds any instance or not.
-
@jsulm i used that to confirm whether qApp holds any instance or not.
@meganathan From documentation:
"A global pointer referring to the unique application object"
https://doc.qt.io/qt-5/qapplication.html#qAppqApp is the pointer to the instance.