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. Cann't write connect in main.cpp
Forum Updated to NodeBB v4.3 + New Features

Cann't write connect in main.cpp

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 3.3k 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.
  • L L.Gogs
    11 Aug 2017, 12:45

    This post is deleted!

    M Offline
    M Offline
    m.sue
    wrote on 11 Aug 2017, 12:46 last edited by
    #3

    Hi @L.Gogs

    Your class does not have a Q_OBJECT macro.

    -Michael.

    L 1 Reply Last reply 11 Aug 2017, 12:47
    2
    • M m.sue
      11 Aug 2017, 12:46

      Hi @L.Gogs

      Your class does not have a Q_OBJECT macro.

      -Michael.

      L Offline
      L Offline
      L.Gogs
      wrote on 11 Aug 2017, 12:47 last edited by
      #4

      @m.sue
      yes I know but when I wrote it, I had errors

      P 1 Reply Last reply 11 Aug 2017, 12:48
      0
      • P Offline
        P Offline
        Pradeep Kumar
        wrote on 11 Aug 2017, 12:48 last edited by
        #5
        class Taz742 : public QObject
        {
        Q_OBJECT 
        public:
            Taz742()
            {
                tm = new QTimer();
            }
        
            QTimer *tm;
            ~Taz742()
            {
                delete tm;
            }
        
        public slots:
            void Print()
            {
                qDebug() << "Taz742";
            }
        };
        

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        L 1 Reply Last reply 11 Aug 2017, 12:51
        0
        • L L.Gogs
          11 Aug 2017, 12:47

          @m.sue
          yes I know but when I wrote it, I had errors

          P Offline
          P Offline
          Pradeep Kumar
          wrote on 11 Aug 2017, 12:48 last edited by
          #6

          @L.Gogs

          can u post what errors occurred.

          Thanks,

          Pradeep Kumar
          Qt,QML Developer

          L 1 Reply Last reply 11 Aug 2017, 12:49
          1
          • P Pradeep Kumar
            11 Aug 2017, 12:48

            @L.Gogs

            can u post what errors occurred.

            Thanks,

            L Offline
            L Offline
            L.Gogs
            wrote on 11 Aug 2017, 12:49 last edited by
            #7

            @Pradeep-Kumar
            of course :))

            undefined reference to 'vtable for Taz742'

            M 1 Reply Last reply 11 Aug 2017, 12:56
            0
            • P Pradeep Kumar
              11 Aug 2017, 12:48
              class Taz742 : public QObject
              {
              Q_OBJECT 
              public:
                  Taz742()
                  {
                      tm = new QTimer();
                  }
              
                  QTimer *tm;
                  ~Taz742()
                  {
                      delete tm;
                  }
              
              public slots:
                  void Print()
                  {
                      qDebug() << "Taz742";
                  }
              };
              

              Thanks,

              L Offline
              L Offline
              L.Gogs
              wrote on 11 Aug 2017, 12:51 last edited by
              #8
              This post is deleted!
              1 Reply Last reply
              0
              • L L.Gogs
                11 Aug 2017, 12:49

                @Pradeep-Kumar
                of course :))

                undefined reference to 'vtable for Taz742'

                M Offline
                M Offline
                m.sue
                wrote on 11 Aug 2017, 12:56 last edited by
                #9

                Hi @L.Gogs

                Your Taz742 destructor is virtual, by inheritance from QObject. A class with virtual functions should be defined in its own file: Taz742.cpp and Taz742.h

                -Michael.

                L 1 Reply Last reply 11 Aug 2017, 12:59
                1
                • M m.sue
                  11 Aug 2017, 12:56

                  Hi @L.Gogs

                  Your Taz742 destructor is virtual, by inheritance from QObject. A class with virtual functions should be defined in its own file: Taz742.cpp and Taz742.h

                  -Michael.

                  L Offline
                  L Offline
                  L.Gogs
                  wrote on 11 Aug 2017, 12:59 last edited by
                  #10

                  @m.sue
                  Thanks...
                  but how can I write connect in main.cpp

                  M 1 Reply Last reply 11 Aug 2017, 13:01
                  1
                  • L L.Gogs
                    11 Aug 2017, 12:59

                    @m.sue
                    Thanks...
                    but how can I write connect in main.cpp

                    M Offline
                    M Offline
                    m.sue
                    wrote on 11 Aug 2017, 13:01 last edited by
                    #11

                    Hi @L.Gogs

                    Just #include the header file. Then you can use your class there

                    -Michael.

                    L 1 Reply Last reply 11 Aug 2017, 13:07
                    1
                    • M m.sue
                      11 Aug 2017, 13:01

                      Hi @L.Gogs

                      Just #include the header file. Then you can use your class there

                      -Michael.

                      L Offline
                      L Offline
                      L.Gogs
                      wrote on 11 Aug 2017, 13:07 last edited by
                      #12

                      @m.sue
                      no no, I want to write connect into main.cpp without any other header or cpp file.

                      M M 2 Replies Last reply 11 Aug 2017, 13:14
                      0
                      • L L.Gogs
                        11 Aug 2017, 13:07

                        @m.sue
                        no no, I want to write connect into main.cpp without any other header or cpp file.

                        M Offline
                        M Offline
                        m.sue
                        wrote on 11 Aug 2017, 13:14 last edited by m.sue 8 Nov 2017, 16:01
                        #13

                        Hi @L.Gogs

                        To be blunt: You have to comply with the rules of the computer language (C++ in this case) or not use it. You cannot discuss such issues with the compiler/linker.

                        -Michael.

                        1 Reply Last reply
                        1
                        • L L.Gogs
                          11 Aug 2017, 13:07

                          @m.sue
                          no no, I want to write connect into main.cpp without any other header or cpp file.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 11 Aug 2017, 13:21 last edited by mrjj 8 Nov 2017, 13:22
                          #14

                          @L.Gogs said in Cann't write connect in main.cpp:

                          no no, I want to write connect into main.cpp without any other header or cpp file.

                          https://stackoverflow.com/questions/34928933/why-is-important-to-include-moc-file-at-end-of-a-qt-source-code-file

                          You can hack it but using a .h file is the right way and besides this approach might have issues.
                          I never used it as its non common to only have .cpp file outside school projects.

                          1 Reply Last reply
                          0

                          12/14

                          11 Aug 2017, 13:07

                          • Login

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