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.

Can you help me for not work in signals problem.

Scheduled Pinned Locked Moved Unsolved General and Desktop
signals emit
9 Posts 4 Posters 817 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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      2
      • SGaistS SGaist

        Hi and welcome to devnet,

        Did you put that all in a single file ?

        N Offline
        N Offline
        nyamnyam
        wrote on last edited by nyamnyam
        #3

        @SGaist yes. i tested for quit console program.

        jsulmJ 1 Reply Last reply
        0
        • N nyamnyam

          @SGaist yes. i tested for quit console program.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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
          • jsulmJ jsulm

            @nyamnyam Move EndChecking to its own header and cpp file

            N Offline
            N Offline
            nyamnyam
            wrote on 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.

            jsulmJ 1 Reply Last reply
            0
            • N nyamnyam

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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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

              JonBJ 1 Reply Last reply
              3
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                • jsulmJ jsulm

                  @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

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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

                    • Login

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