Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QApplication in library project
Forum Updated to NodeBB v4.3 + New Features

QApplication in library project

Scheduled Pinned Locked Moved Unsolved General and Desktop
libraryqapplicationqeventloop
17 Posts 3 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

    Any chances of having static objects from QObject based classes ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    SlaneS 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Any chances of having static objects from QObject based classes ?

      SlaneS Offline
      SlaneS Offline
      Slane
      wrote on last edited by Slane
      #5

      @SGaist In which part ? Core or GUI ?

      Core have:

      static CoreApp* CoreApp::CoreAppInstance();
      static void TerminateCoreApp();

      static CoreApp* instance;

      GUI haven't static methode and objects.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        That doesn't matter, you should not have static QObject based objects.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • SlaneS Offline
          SlaneS Offline
          Slane
          wrote on last edited by Slane
          #7

          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 ?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #8

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • SlaneS Offline
              SlaneS Offline
              Slane
              wrote on last edited by
              #9

              I see... so I haven't static object... I don't find the problem...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • SlaneS Offline
                  SlaneS Offline
                  Slane
                  wrote on last edited by Slane
                  #11

                  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.

                  jsulmJ 1 Reply Last reply
                  0
                  • SlaneS Slane

                    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.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @Slane What is CoreApp?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    SlaneS 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Slane What is CoreApp?

                      SlaneS Offline
                      SlaneS Offline
                      Slane
                      wrote on last edited by
                      #13

                      @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;
                      };
                      
                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        What in Database since it's where you seem to have trouble ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • SlaneS Offline
                          SlaneS Offline
                          Slane
                          wrote on last edited by Slane
                          #15

                          Minimal code that don't work :

                          In exe :

                          GUI.pro

                          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

                          CoreApp.pro

                          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)

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            Since you modified your code, what do you mean by "doesn't work" ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            SlaneS 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Since you modified your code, what do you mean by "doesn't work" ?

                              SlaneS Offline
                              SlaneS Offline
                              Slane
                              wrote on last edited by Slane
                              #17

                              @SGaist I wish mean throw this message : QEventLoop: Cannot be used without QApplication

                              But this problem is no more. I have delete the project and create un other without dll...
                              It's not the best solution but it's gona work.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved