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't create macro for QTextStream manipulator functions
Forum Updated to NodeBB v4.3 + New Features

Can't create macro for QTextStream manipulator functions

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 358 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I'm creating some macros to ease transition from Qt5 to Qt6 for some of my shared code. For some reason, the QTextStream manipulator functions just don't want to be used in a macro!

    Here's example 1, and under Qt6 the Qt::endl line causes compiler error: "MyLib::Qt has not been declared". This code is in my compat.h file which does not set a namespace. Why is it even referencing MyLib:: ?? Notice the SkipEmbyParts macro works fine.

    // Example 1
    #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
    #define QT_COMPAT_SKIPEMPTYPARTS                   QString::SkipEmptyParts
    #define QT_COMPAT_ENDL                             "\n"
    #else
    #define QT_COMPAT_SKIPEMPTYPARTS                   Qt::SkipEmptyParts
    #define QT_COMPAT_ENDL                             Qt::endl
    #endif
    

    And here's example number 2, in this case the ::Qt::flush causes compiler error: "Unexpected qualified id before '::' token". I tried to prefix my manipulator with :: so that no higher level namespace would be assumed...but that chokes too.

    // Example 2
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    #define QT_COMPAT_FLUSH                            flush
    #else
    #define QT_COMPAT_FLUSH                            ::Qt::flush
    #endif
    

    Can someone help me fix my macros?

    1 Reply Last reply
    0
    • ocgltdO Offline
      ocgltdO Offline
      ocgltd
      wrote on last edited by
      #3

      Ok, my error. I was USING the macro incorrectly in one spot, writing MyLib::QT_COMPAT_FLUSH. Once I just used the macro name all worked as expected.

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

        Hi,

        Can you provide a minimal buildable example showing this ?

        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
        • ocgltdO Offline
          ocgltdO Offline
          ocgltd
          wrote on last edited by
          #3

          Ok, my error. I was USING the macro incorrectly in one spot, writing MyLib::QT_COMPAT_FLUSH. Once I just used the macro name all worked as expected.

          1 Reply Last reply
          1
          • ocgltdO ocgltd has marked this topic as solved on

          • Login

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