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. operator<< has too many parameters
Forum Updated to NodeBB v4.3 + New Features

operator<< has too many parameters

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.7k 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.
  • VolebabV Offline
    VolebabV Offline
    Volebab
    wrote on last edited by
    #1

    I'm trying to override the operator << in order to implement a kind of to string using QDebug and for other usage cases, the problem is that I'm getting an error:

    QDataStream& operator<<(QDataStream &stream, const Namer &namer)
    {
        return stream << "hi";
    }
    
    Namer namer;
    qDebug() << namer;
    

    binary 'operator <<' has too many parameters
    binary '<<' : no operator found which takes a left-hand operand of type 'QDebug' (or there is no acceptable conversion) ...

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

      Hi,

      If you would like to send your class through QDebug you need to implement the stream operator for QDebug i.e.:

      QDebug operator <<(QDebug dbg, const Name& namer)
      {
      dbg << namer.myNiceMethod();
      return dbg;
      }
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      VolebabV 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        If you would like to send your class through QDebug you need to implement the stream operator for QDebug i.e.:

        QDebug operator <<(QDebug dbg, const Name& namer)
        {
        dbg << namer.myNiceMethod();
        return dbg;
        }
        
        VolebabV Offline
        VolebabV Offline
        Volebab
        wrote on last edited by
        #3

        @SGaist It's not only for QDebug, but in cases of strings. I thought that QDataStream would do the job.

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

          If you want to support several streams then you have to implement them separately.

          As for strings don't you mean QTextStream ?

          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
          • VolebabV Offline
            VolebabV Offline
            Volebab
            wrote on last edited by
            #5

            You are right, I checked a few sources and now it's working, thank you.

            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