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. Implementing debug for my class
Forum Updated to NodeBB v4.3 + New Features

Implementing debug for my class

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 987 Views 2 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    I have written a 3D point class because all Qt classes use float and not qreal. I need double. I would like to have the coordinates written to QDebug(); however, I keep getting compile errors.

    error: ‘QDebug MyPoint3D::operator<<(QDebug, const MyPoint3D&)’ must take exactly one argument
         QDebug operator<< (QDebug debug, const MyPoint3D &mc);
                                                             ^
    QDebug operator<< (QDebug debug, const MyPoint3D &mc);
    
    QDebug <<(QDebug debug, const MyPoint3D &mc)
    {
        QDebugStateSaver saver(debug);
        debug.nospace() << mc.x << mc.y << mc.z;
        return debug;
    }
    

    What am I doing wrong?

    aha_1980A 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      Did you add the overload inside the class ?
      The error suggest that.

      Normally its goes

      class X {
      ..
      };

      QDebug operator<< (QDebug debug, const X &mc);

      and then implementation in . cpp

      1 Reply Last reply
      2
      • O ofmrew

        I have written a 3D point class because all Qt classes use float and not qreal. I need double. I would like to have the coordinates written to QDebug(); however, I keep getting compile errors.

        error: ‘QDebug MyPoint3D::operator<<(QDebug, const MyPoint3D&)’ must take exactly one argument
             QDebug operator<< (QDebug debug, const MyPoint3D &mc);
                                                                 ^
        QDebug operator<< (QDebug debug, const MyPoint3D &mc);
        
        QDebug <<(QDebug debug, const MyPoint3D &mc)
        {
            QDebugStateSaver saver(debug);
            debug.nospace() << mc.x << mc.y << mc.z;
            return debug;
        }
        

        What am I doing wrong?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by aha_1980
        #3

        @ofmrew You need to declare the function outside your class MyPoint3D.

        Edit: exactly as @mrjj says.

        Qt has to stay free or it will die.

        O 1 Reply Last reply
        2
        • aha_1980A aha_1980

          @ofmrew You need to declare the function outside your class MyPoint3D.

          Edit: exactly as @mrjj says.

          O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          @aha_1980 & mrjj Yes, I remember that from serialization. Now it the implementation that gives the error, namely:

           error: expected unqualified-id before ‘<<’ token
           QDebug <<(QDebug debug, const MyPoint3D &mc)
                  ^
          

          What is the problem?

          aha_1980A 1 Reply Last reply
          0
          • O ofmrew

            @aha_1980 & mrjj Yes, I remember that from serialization. Now it the implementation that gives the error, namely:

             error: expected unqualified-id before ‘<<’ token
             QDebug <<(QDebug debug, const MyPoint3D &mc)
                    ^
            

            What is the problem?

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ofmrew You are missing "operator". Just do it like @mrjj said in post 2.

            Qt has to stay free or it will die.

            O 1 Reply Last reply
            2
            • aha_1980A aha_1980

              @ofmrew You are missing "operator". Just do it like @mrjj said in post 2.

              O Offline
              O Offline
              ofmrew
              wrote on last edited by
              #6

              @aha_1980 Thanks to both of you for your help. I had that, but was distracted by the first problem.

              aha_1980A 1 Reply Last reply
              1
              • O ofmrew

                @aha_1980 Thanks to both of you for your help. I had that, but was distracted by the first problem.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @ofmrew So please mark the topic as SOLVED. Thanks!

                Qt has to stay free or it will die.

                1 Reply Last reply
                1
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Just as a final note.
                  If you need to write out private variables, you need
                  class MyPoint3D {
                  friend QDebug operator<< (QDebug d, const MyPoint3D &mc);
                  ...
                  }

                  1 Reply Last reply
                  2

                  • Login

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