Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Can you help me for not work in signals problem.

    General and Desktop
    signals emit
    4
    9
    287
    Loading More Posts
    • 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.
    • N
      nyamnyam last edited by

      Hello.
      I think it's beginner's problem.. but i'm not solve this problem in 5 hours.

      this code is console source and error message is shown.

      main.obj:-1: error: LNK2019: "public: void __cdecl EndChecking::quitSignal(void)" (?quitSignal@EndChecking@@QEAAXXZ) external sign (reference location: "protected: virtual void __cdecl EndChecking::run(void)" (?run@EndChecking@@MEAAXXZ) function )에서 확인하지 못했습니다.

      how do i modify it? i can't understand where error code is.
      Please help me for this situations.

      Thx.

      in source is below

      #include <QCoreApplication>
      #include <QThread>
      #include <iostream>

      class EndChecking : public QThread
      {
      Q_OBJECT
      protected:
      virtual void run() override;

      signals: void quitSignal();
      };

      void EndChecking::run()
      {
      char c = NULL;

      while (true)
      {
          std::cin >> c;
      
          if (c == 'q' || c == 'Q')
              emit quitSignal();
      }
      

      }

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      std::cout << "type Q to exit Program" << std::endl;
      
      EndChecking* pchk = new EndChecking();
      QObject::connect(pchk, SIGNAL(quitSignal()), &a, SLOT(quit()));
      pchk->start();
      
      return a.exec();
      

      }

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Did you put that all in a single file ?

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

        N 1 Reply Last reply Reply Quote 2
        • N
          nyamnyam @SGaist last edited by nyamnyam

          @SGaist yes. i tested for quit console program.

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @nyamnyam last edited by

            @nyamnyam Move EndChecking to its own header and cpp file

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

            N 1 Reply Last reply Reply Quote 3
            • N
              nyamnyam @jsulm last edited by

              @jsulm Wow Thx.. it is worked.
              But, i don't understand why this dvede in different cpp n h files.
              I think that (devide and combine classes ) is same.
              Can you help me why combine file is not work?
              First of all, thak you for solving my problem.
              Thx.

              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @nyamnyam last edited by

                @nyamnyam The reason for that is that QObject based classes needs to be parsed by moc Qt tool which generates code for signals/slots. See https://doc.qt.io/qt-5/why-moc.html

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

                JonB 1 Reply Last reply Reply Quote 3
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  If you have everything in a single file you need to add:

                  #include "main.moc"
                  

                  At the bottom of the file and re-run qmake so that moc is run on that cpp file and thus the corresponding code is generated.

                  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 Reply Quote 1
                  • JonB
                    JonB @jsulm last edited by

                    @jsulm said in Can you help me for not work in signals problem.:

                    Move EndChecking to its own header and cpp file
                    The reason for that is that QObject based classes needs to be parsed by moc Qt tool which generates code for signals/slots

                    Ah ha! :) Now that I am doing C++ with Qt: could you be specific about what requirements/restrictions this imposes? Does this mean, say, that you cannot have two classes derived from QObject in the same .cpp/.h as one another?

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      No particular restrictions. As written before, QObject based classes are usually declared in their own header. Nothing prevents you from having them in a cpp file, you just have to put the corresponding include at the end so they are also parsed by moc for QObject based classes in them.

                      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 Reply Quote 1
                      • First post
                        Last post