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. Signal from Application class?
Forum Updated to NodeBB v4.3 + New Features

Signal from Application class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 828 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I've been writing an application for several weeks now, the main class is derived from QApplication.

    class Trainer : public QApplication
    

    Today I tried to implement a signal from the main application so that if an error occurs it emits a signal:

    signals:
        void dbError(const QSqlError& crErr);
    

    When building this resulted in:

    C2338: No Q_OBJECT in the class with the signal
    

    So I added Q_OBJECT to the class and rebuilt, now the errors are:

    LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
    LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
    

    This is the actual emit in the class:

    emit Trainer::mspApp->dbError(err);
    

    mspApp is defined as:

    static Trainer* mspApp;
    

    Which is in the Trainer class and in the module:

    Trainer* Trainer::mspApp = nullptr;
    

    This static pointer is initialised in the class constructor:

    Trainer::mspApp = this;
    

    What am I not doing?

    Kind Regards,
    Sy

    jsulmJ J.HilkJ KroMignonK 3 Replies Last reply
    0
    • SPlattenS SPlatten

      I've been writing an application for several weeks now, the main class is derived from QApplication.

      class Trainer : public QApplication
      

      Today I tried to implement a signal from the main application so that if an error occurs it emits a signal:

      signals:
          void dbError(const QSqlError& crErr);
      

      When building this resulted in:

      C2338: No Q_OBJECT in the class with the signal
      

      So I added Q_OBJECT to the class and rebuilt, now the errors are:

      LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
      LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
      

      This is the actual emit in the class:

      emit Trainer::mspApp->dbError(err);
      

      mspApp is defined as:

      static Trainer* mspApp;
      

      Which is in the Trainer class and in the module:

      Trainer* Trainer::mspApp = nullptr;
      

      This static pointer is initialised in the class constructor:

      Trainer::mspApp = this;
      

      What am I not doing?

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

      @SPlatten said in Signal from Application class?:

      What am I not doing?

      Did you do complete rebuild after adding Q_OBJECT macro?

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

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @SPlatten said in Signal from Application class?:

        What am I not doing?

        Did you do complete rebuild after adding Q_OBJECT macro?

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #3

        @jsulm , yes, cleaned, then remake then rebuild, before posting here.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • SPlattenS SPlatten

          I've been writing an application for several weeks now, the main class is derived from QApplication.

          class Trainer : public QApplication
          

          Today I tried to implement a signal from the main application so that if an error occurs it emits a signal:

          signals:
              void dbError(const QSqlError& crErr);
          

          When building this resulted in:

          C2338: No Q_OBJECT in the class with the signal
          

          So I added Q_OBJECT to the class and rebuilt, now the errors are:

          LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
          LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
          

          This is the actual emit in the class:

          emit Trainer::mspApp->dbError(err);
          

          mspApp is defined as:

          static Trainer* mspApp;
          

          Which is in the Trainer class and in the module:

          Trainer* Trainer::mspApp = nullptr;
          

          This static pointer is initialised in the class constructor:

          Trainer::mspApp = this;
          

          What am I not doing?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @SPlatten you don't have to reinvent the wheel you know, especially in relation to static QObjects, that are tricky in their own right. Especially as the instantiation order is important

          you're deriving from QApplication, so you have the qApp macro at your disposal

          #define qApp QCoreApplication::instance()
          

          or use the QCoreApplication::instance() call direct. and object cast it.

          If you're copy pasted this, than you have an error in your code, as this should be QApplication not Application

          class Trainer : public Application
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          SPlattenS 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @SPlatten you don't have to reinvent the wheel you know, especially in relation to static QObjects, that are tricky in their own right. Especially as the instantiation order is important

            you're deriving from QApplication, so you have the qApp macro at your disposal

            #define qApp QCoreApplication::instance()
            

            or use the QCoreApplication::instance() call direct. and object cast it.

            If you're copy pasted this, than you have an error in your code, as this should be QApplication not Application

            class Trainer : public Application
            
            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #5

            @J-Hilk, thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.

            Sorry, again Application is supposed to read QApplication that was a typo adding this post, the laptop I'm using on has issues and cannot post to this forum. So I have to type it all in on my iMac.

            Kind Regards,
            Sy

            J.HilkJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @J-Hilk, thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.

              Sorry, again Application is supposed to read QApplication that was a typo adding this post, the laptop I'm using on has issues and cannot post to this forum. So I have to type it all in on my iMac.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @SPlatten said in Signal from Application class?:

              thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.

              C++ dynamic_cast() or qobject_cast() NOT static_cast!

              My heart 😱
              šŸ˜‰


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              SPlattenS 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @SPlatten said in Signal from Application class?:

                thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.

                C++ dynamic_cast() or qobject_cast() NOT static_cast!

                My heart 😱
                šŸ˜‰

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                @J-Hilk , ok, noted for future, but not an issue here as I'm creating a pointer to my own instance.

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • SPlattenS SPlatten

                  I've been writing an application for several weeks now, the main class is derived from QApplication.

                  class Trainer : public QApplication
                  

                  Today I tried to implement a signal from the main application so that if an error occurs it emits a signal:

                  signals:
                      void dbError(const QSqlError& crErr);
                  

                  When building this resulted in:

                  C2338: No Q_OBJECT in the class with the signal
                  

                  So I added Q_OBJECT to the class and rebuilt, now the errors are:

                  LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
                  LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
                  

                  This is the actual emit in the class:

                  emit Trainer::mspApp->dbError(err);
                  

                  mspApp is defined as:

                  static Trainer* mspApp;
                  

                  Which is in the Trainer class and in the module:

                  Trainer* Trainer::mspApp = nullptr;
                  

                  This static pointer is initialised in the class constructor:

                  Trainer::mspApp = this;
                  

                  What am I not doing?

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #8

                  @SPlatten said in Signal from Application class?:

                  So I added Q_OBJECT to the class and rebuilt, now the errors are:
                  LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...
                  LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &) ...

                  The only reason I am aware about for this issue is that the MOC has not been called.

                  For QMake projects, you just have to rerun QMake (Build => run qmake), and rebuild the project.
                  For CMake projects, I don't know, there must be something equivalent.

                  Or simply delete the build directory.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  3

                  • Login

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