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. Can you help me for not work in signals problem.
QtWS25 Last Chance

Can you help me for not work in signals problem.

Scheduled Pinned Locked Moved Unsolved General and Desktop
signals emit
9 Posts 4 Posters 805 Views
  • 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 Offline
    N Offline
    nyamnyam
    wrote on 2 Apr 2020, 17:17 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Apr 2020, 17:28 last edited by
      #2

      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 3 Apr 2020, 01:08
      2
      • S SGaist
        2 Apr 2020, 17:28

        Hi and welcome to devnet,

        Did you put that all in a single file ?

        N Offline
        N Offline
        nyamnyam
        wrote on 3 Apr 2020, 01:08 last edited by nyamnyam 4 Mar 2020, 01:10
        #3

        @SGaist yes. i tested for quit console program.

        J 1 Reply Last reply 3 Apr 2020, 05:18
        0
        • N nyamnyam
          3 Apr 2020, 01:08

          @SGaist yes. i tested for quit console program.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 3 Apr 2020, 05:18 last edited by
          #4

          @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 3 Apr 2020, 05:30
          3
          • J jsulm
            3 Apr 2020, 05:18

            @nyamnyam Move EndChecking to its own header and cpp file

            N Offline
            N Offline
            nyamnyam
            wrote on 3 Apr 2020, 05:30 last edited by
            #5

            @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.

            J 1 Reply Last reply 3 Apr 2020, 05:36
            0
            • N nyamnyam
              3 Apr 2020, 05:30

              @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.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 3 Apr 2020, 05:36 last edited by
              #6

              @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

              J 1 Reply Last reply 3 Apr 2020, 20:55
              3
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 3 Apr 2020, 19:19 last edited by
                #7

                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
                1
                • J jsulm
                  3 Apr 2020, 05:36

                  @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

                  J Offline
                  J Offline
                  JonB
                  wrote on 3 Apr 2020, 20:55 last edited by
                  #8

                  @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
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 3 Apr 2020, 22:11 last edited by
                    #9

                    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
                    1

                    5/9

                    3 Apr 2020, 05:30

                    • Login

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