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. qDebug overload, return non const function?
QtWS25 Last Chance

qDebug overload, return non const function?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdebug
4 Posts 2 Posters 976 Views
  • 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
    Dariusz
    wrote on 22 Sept 2018, 09:22 last edited by Dariusz
    #1

    Hey

    I'm trying to overload qDebug but I struggle to solve some of the things. The qDebug () friend class is located in base class, and then I wish to output data via virtual function to get the inherited data output... In any case here is the test :

        virtual QDebug getDebugData(QDebug stream){ // if I add )const{ then the error1 below goes away but I get new error2 
            stream <<"inherited data?";
            return stream;
        }
        
        friend QDebug operator<<(QDebug stream, const testObject &object) {
            stream << object.getDebugData(stream); // error1 function is not marked const. // error2 if above is const then this flags as "Invalid operands to binary expression ('QDebug' to 'QDebug')
            stream <<"this Is base class"; 
            return stream;
        }
    

    I kinda get the issue with const but I dont. I struggle with them lately. Would any1 mind helping me out with this?

    TIA

    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 22 Sept 2018, 09:28 last edited by
      #2

      Your getDebugData() should return a QString and should be marked as const since you're working on a const object inside operator<<()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on 22 Sept 2018, 13:05 last edited by
        #3

        Awesome thanks! That worked :- )

        But I run in to a wall, the virtual QString getDebugData never actually calls the upper inherited classes getDebugData function. I just end up with base class debug even tho I debug()<<inheritedObject; Any hints as to why that would not work?

        Regards
        Dariusz
        TIA

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 22 Sept 2018, 14:15 last edited by
          #4

          @Dariusz said in qDebug overload, return non const function?:

          the virtual QString getDebugData never actually calls the upper inherited classes getDebugData

          I don't understand - what do you mean here? I don't see that you call the base class implementation in this function anywhere so how should it be called?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          1/4

          22 Sept 2018, 09:22

          • Login

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