QApplication in library project
-
Ha... so I gonna to find another way... Without static method and object...
But why we shouldn't create static object based on QObject ?
EDIT : My bad... it's not static QObject based object but static ptr over QObject based object... it's the same case ?
-
I didn't talk about static methods at all.
QApplication does some initialisation. Your static QObject based classed would be created before QApplication and thus would be in an "uninitialised" state.
No, static pointers are not concerned.
-
With the code you provided, there's nothing that can really be guessed except that you might have something wrong in your Database class.
On an unrelated note, it seems you are not cleaning anything when destroying your CoreApp instance. At least from the code you posted.
-
I can't post all the code... they are no other thing like static object based on QObject who can throw this error ?
@SGaist said in QApplication in library project:
On an unrelated note, it seems you are not cleaning anything when destroying your CoreApp instance. At least from the code you posted.
The database and thread aren't destroy by this way.
-
@jsulm CoreApp is the wrapper of all functionality in the DLL
Currently :
#include "coreapp_global.h" #include <QObject> class Database; class COREAPPSHARED_EXPORT CoreApp : public QObject { Q_OBJECT public: static CoreApp* CoreAppInstance(); static void TerminateCoreApp(); private: static CoreApp* instance; CoreApp(); ~CoreApp(); Database* database; QThread* databaseThread; };
-
What in Database since it's where you seem to have trouble ?
-
Minimal code that don't work :
In exe :
QT = core gui widgets TARGET = GUI TEMPLATE = app LIBS += -LD:\Data\Code\Projet\build-CoreApp\debug -lCoreApp DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ Core.cpp HEADERS += \ Core.h
main.cpp
#include "Core.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Core core; return a.exec(); }
core.h
#ifndef CORE_H #define CORE_H class Core { public: Core(); }; #endif // CORE_H
core.cpp
#include "Core.h" #include "../CoreApp/CoreApp.h" Core::Core() { new CoreApp(); } void Core::start() { } Core::~Core() { CoreApp::TerminateCoreApp(); }
In dll
QT += sql core TARGET = CoreApp TEMPLATE = lib DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ CoreApp.cpp \ HEADERS += \ CoreApp.h \ CoreApp_global.h \ unix { target.path = /usr/lib INSTALLS += target }
CoreApp.h
#ifndef COREAPP_H #define COREAPP_H #include "coreapp_global.h" #include <QObject> class COREAPPSHARED_EXPORT CoreApp: public QObject { Q_OBJECT public: CoreApp(); private: QThread* databaseThread; }; #endif // COREAPP_H
coreapp_gloable.h
#ifndef COREAPP_GLOBAL_H #define COREAPP_GLOBAL_H #include <QtCore/qglobal.h> #if defined(COREAPP_LIBRARY) # define COREAPPSHARED_EXPORT Q_DECL_EXPORT #else # define COREAPPSHARED_EXPORT Q_DECL_IMPORT #endif #endif // COREAPP_GLOBAL_H
CoreApp.cpp
#include "CoreApp.h" #include <QThread> #include <QDebug> #include <QApplication> CoreApp::CoreApp() { this->databaseThread = new QThread(); this->databaseThread->start(); }
I think the probleme don't come from the code...
(the code are handmodified) -
Since you modified your code, what do you mean by "doesn't work" ?