Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Strange Error message

Strange Error message

Scheduled Pinned Locked Moved C++ Gurus
16 Posts 3 Posters 4.8k 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.
  • D Offline
    D Offline
    Dn588
    wrote on last edited by
    #1

    Hi all

    I am getting a strange error message i've never seen before when trying to run the below program.

    error message:
    in copy constructor 'staff::staff(const staff&)'

    'QObject::QObject(const QObject)' is private within this context

    my code:
    https://www.dropbox.com/sh/wowwansg38mortr/AAD8o15lr1paOb7SJyUC73RMa?dl=0

    I understand that private member functions can only be called from the same class but not sure what that means in this instance. Am I calling the copy constructor of staff somewhere I shouldn't be calling it from?

    Thanks

    Deon

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Looks like you are passing some object by value. Since copy constructor is disabled. Try passing reference.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dn588
        wrote on last edited by
        #3

        Hi Dheerendra there was a constructor in the staffList class where I passed a staff object. I fixed that but still no luck. i've gone over everything a few times and don't see any other functions with objects in their parameter list... Is there any way to see where this issue is coming from? When I click on the error message it opens QObject.h which doesn't help much...

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Just try clean once, run qmake and rebuild. If you still face the issue, drop me the code. I will check and revert quickly.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dn588
            wrote on last edited by
            #5

            Tried that but still no change...
            Thanks for taking a look

            my code:

            https://www.dropbox.com/sh/qkujdbs0trjksvq/AADEV3y0xMyQ__WyP6IkzLOha?dl=0

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You can't copy QObject derived class so addToList should have a pointer to staff as parameter

              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
              0
              • D Offline
                D Offline
                Dn588
                wrote on last edited by
                #7

                Thanks a lot SGaist

                I now get another error I don't understand...

                error: expected unqualified-id before if'

                At the code:

                @
                QFile file("staff.txt");

                if (!file.open(QIODevice:: WriteOnly | QIODevice:: Text))
                return;
                @

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Is this code located in a function ?

                  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
                  0
                  • D Offline
                    D Offline
                    Dn588
                    wrote on last edited by
                    #9

                    No it's not could that be it?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      You can't write code freely anywhere in a file in C/C++ It needs to be inside a function/method.

                      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
                      0
                      • D Offline
                        D Offline
                        Dn588
                        wrote on last edited by
                        #11

                        Thanks I moved it into a function. now i'm getting an error invalid conversion from int to char* in the following function @QString staff::toString() {
                        return QString("Name: %1 \n Birth Date: %2 \n Staff Type: %3 \n \n").arg(s_name).arg(s_birthDate.toString('yyyyMMdd').arg(getTypeString()));
                        }@

                        there's no int in this function though? Could it be the enum s_type? I created a function getTypeString @
                        staff::getTypeString() {
                        return property("Type").toString();
                        }
                        that's supposed to return a QString...

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          The only error I see currently is that you have a misplace arg. You attached your third parameter to the s_birthDate.toString call

                          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
                          0
                          • D Offline
                            D Offline
                            Dn588
                            wrote on last edited by
                            #13

                            So should the parameters start at %0?

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Nop, that part is fine

                              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
                              0
                              • D Offline
                                D Offline
                                Dn588
                                wrote on last edited by
                                #15

                                which third parameter did I attach to s_birthDate.toString()?

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @
                                  QString("Name: %1 \n Birth Date: %2 \n Staff Type: %3 \n \n")
                                  .arg(s_name) << correct
                                  .arg(s_birthDate.toString('yyyyMMdd').arg(getTypeString() << arg of toString rather than arg for QString()
                                  @

                                  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
                                  0

                                  • Login

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