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. Why i cant create instance of the simpliest custom class?
Forum Updated to NodeBB v4.3 + New Features

Why i cant create instance of the simpliest custom class?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.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.
  • B Offline
    B Offline
    Bonnie
    wrote on last edited by Bonnie
    #2

    Seems that you didn't implement the constructor of timeWorker.

    EngelardE 1 Reply Last reply
    1
    • B Bonnie

      Seems that you didn't implement the constructor of timeWorker.

      EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by
      #3

      @Bonnie Yes, problem with that, but i peeked on my former projects, and in those, worker classes have empty constructors, and everything there looks the same. But there it works, and in this new it does not. Thats how my class looks like:

      alt text

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4

        timeWorker(); is not an empty constructor, it's a consructor declaration. You are telling the compiler to trust you that the constructor exists but if you don't actually implement it (empty or not) than the compiler complains because you lied to it.

        If you don't have to do anything in the constructor, however, the easiest way is typing using QObject::QObject; instead of decalring constructors, this tells the compiler to just use QObject constructors for your class

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        EngelardE 1 Reply Last reply
        3
        • VRoninV VRonin

          timeWorker(); is not an empty constructor, it's a consructor declaration. You are telling the compiler to trust you that the constructor exists but if you don't actually implement it (empty or not) than the compiler complains because you lied to it.

          If you don't have to do anything in the constructor, however, the easiest way is typing using QObject::QObject; instead of decalring constructors, this tells the compiler to just use QObject constructors for your class

          EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #5

          @VRonin Why i did'nt do anything like this before and everything was fine with empty constructors?

          JonBJ 1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #6

            Again. That's not an empty constructor.
            This is an empty constructor: timeWorker(){}
            This is a constructor declaration timeWorker();

            This is immutable from the dawn of C++

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            4
            • EngelardE Engelard

              @VRonin Why i did'nt do anything like this before and everything was fine with empty constructors?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #7

              @Engelard said in Why i cant create instance of the simpliest custom class?:

              @VRonin Why i did'nt do anything like this before and everything was fine with empty constructors?

              As @VRonin says, so why don't you show us what you did before which worked?

              EngelardE 1 Reply Last reply
              0
              • JonBJ JonB

                @Engelard said in Why i cant create instance of the simpliest custom class?:

                @VRonin Why i did'nt do anything like this before and everything was fine with empty constructors?

                As @VRonin says, so why don't you show us what you did before which worked?

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by
                #8

                @JonB I'd show you completelly the same. Empty constructors of the worker class, but those working.

                alt text

                By empty i mean it is empty, no need to show worker::worker(){} stuff, i suppose it should be obvious.

                JonBJ 1 Reply Last reply
                0
                • EngelardE Engelard

                  @JonB I'd show you completelly the same. Empty constructors of the worker class, but those working.

                  alt text

                  By empty i mean it is empty, no need to show worker::worker(){} stuff, i suppose it should be obvious.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #9

                  @Engelard

                  By empty i mean it is empty, no need to show worker::worker(){} stuff, i suppose it should be obvious.

                  What you have elsewhere in your code might be obvious to you but is not obvious to us when we try to answer user questions. Do you mean that in addition to the .h file you show you do also have

                  worker::worker()
                  {
                  }
                  

                  in the .cpp file?

                  Cutting a long story short, if you feel your code is correct and you are getting irritated by these questions, have you deleted all files from the debug/release compilation directory and re-run qmake on your project? Especially if you, say, add or remove Q_OBJECT from the header, but also other cases, so make sure you have done this.

                  Further, from the error message I see it mentions "file not found", don't know if that is relevant. And it is looking for a constructor which accepts a class QObject * parent, like https://doc.qt.io/qt-5/qobject.html#QObject does, which your timeWorker() does not.

                  Thoughts for you, only trying to be helpful....

                  1 Reply Last reply
                  3
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #10

                    Unless you have a definition somewhere else (usually in the .cpp file) a constructur declaration is not enough. This is not related to Qt, this is pure C++ and it has been this way since the language existed

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    EngelardE 1 Reply Last reply
                    2
                    • VRoninV VRonin

                      Unless you have a definition somewhere else (usually in the .cpp file) a constructur declaration is not enough. This is not related to Qt, this is pure C++ and it has been this way since the language existed

                      EngelardE Offline
                      EngelardE Offline
                      Engelard
                      wrote on last edited by
                      #11

                      @VRonin said in Why i cant create instance of the simpliest custom class?:

                      Unless you have a definition somewhere else (usually in the .cpp file) a constructur declaration is not enough. This is not related to Qt, this is pure C++ and it has been this way since the language existed

                      I ofc have the proper declaration and definition, as i said i have bunch of previous projects which made exactly that way, and those working.

                      Cutting a long story short, if you feel your code is correct and you are getting irritated by these questions, have you deleted all files from the debug/release compilation directory and re-run qmake on your project?

                      Irritated indeed, because i know the basics of C++ well, and i also know for 100% that i'm doing everything right but it get to me like something wrong, and it is - again Qt bug(or call that whatever you preffer but it is a bug).

                      I deleted debug-release folders, Rerun Qmake and now it SUDDENLY tell me that no errors and everything run fine!

                      JonBJ 1 Reply Last reply
                      0
                      • EngelardE Engelard

                        @VRonin said in Why i cant create instance of the simpliest custom class?:

                        Unless you have a definition somewhere else (usually in the .cpp file) a constructur declaration is not enough. This is not related to Qt, this is pure C++ and it has been this way since the language existed

                        I ofc have the proper declaration and definition, as i said i have bunch of previous projects which made exactly that way, and those working.

                        Cutting a long story short, if you feel your code is correct and you are getting irritated by these questions, have you deleted all files from the debug/release compilation directory and re-run qmake on your project?

                        Irritated indeed, because i know the basics of C++ well, and i also know for 100% that i'm doing everything right but it get to me like something wrong, and it is - again Qt bug(or call that whatever you preffer but it is a bug).

                        I deleted debug-release folders, Rerun Qmake and now it SUDDENLY tell me that no errors and everything run fine!

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #12

                        @Engelard
                        That's why I suggested the clean-out-and-re-make! It's not a Qt bug, but it is a problem with Qt Creator/qmake.

                        It is just life/how it is that when you find inexplicable compilation/link errors it may be that cached previous compilation stuff is the culprit. I don't like it any more than you do, but I often find I have to do this to get it to sort itself out, I agree it should be more robust at noticing changes.... I happen to know, I believe, that for example adding Q_OBJECT to an existing .h file seems to require clean-and-remake.

                        EngelardE 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Engelard
                          That's why I suggested the clean-out-and-re-make! It's not a Qt bug, but it is a problem with Qt Creator/qmake.

                          It is just life/how it is that when you find inexplicable compilation/link errors it may be that cached previous compilation stuff is the culprit. I don't like it any more than you do, but I often find I have to do this to get it to sort itself out, I agree it should be more robust at noticing changes.... I happen to know, I believe, that for example adding Q_OBJECT to an existing .h file seems to require clean-and-remake.

                          EngelardE Offline
                          EngelardE Offline
                          Engelard
                          wrote on last edited by
                          #13

                          @JonB Tnx for reminding me about that delete/rebuild way.

                          1 Reply Last reply
                          0

                          • Login

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