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. Can qDebug() print a c struct instance?
Forum Updated to NodeBB v4.3 + New Features

Can qDebug() print a c struct instance?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 4.0k 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.
  • M Offline
    M Offline
    Mr Pang
    wrote on last edited by
    #1

    Just c struct, not c++ class.

    kshegunovK JohanSoloJ 2 Replies Last reply
    0
    • M Mr Pang

      Just c struct, not c++ class.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Mr-Pang
      Hello,
      A C struct is not much different from a C++ class beside the default access specifier being public. That said, it is possible to write a custom type to the debug stream if you provide your own operator for that. There's an example in the documentation how this could be achieved.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • M Mr Pang

        Just c struct, not c++ class.

        JohanSoloJ Offline
        JohanSoloJ Offline
        JohanSolo
        wrote on last edited by
        #3

        @Mr-Pang said:

        Just c struct, not c++ class.

        To complete @kshegunov's answer, qDebug() cannot magically print a C++ class. It can display information for all classes which have an overload of operator<<. Therefore, the same is also valid for a POD structure (aka C struct).

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mr Pang
          wrote on last edited by
          #4

          Got it. 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