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. Segfault after removal of Q_OBJECT macro - what "other services" may fail
Forum Updated to NodeBB v4.3 + New Features

Segfault after removal of Q_OBJECT macro - what "other services" may fail

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 440 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.
  • J Offline
    J Offline
    Joachim W
    wrote on last edited by
    #1

    The QObject doc page says: »The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.«

    Is there an authorative list of these »other services«? How do I see from a class definition whether any of them are used and require the Q_OBJECT macro?

    In a big project, I removed the Q_OBJECT from class definitions if the class contains neither signals nor slots, nor makes use of .ui files. This went well in most cases, but in a few cases led to segfaults.

    Is it normal and expected behavior that missing Q_OBJECT macro is not detected at compile or link time, but corrupts the runtime?

    Christian EhrlicherC 1 Reply Last reply
    0
    • J Joachim W

      The QObject doc page says: »The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.«

      Is there an authorative list of these »other services«? How do I see from a class definition whether any of them are used and require the Q_OBJECT macro?

      In a big project, I removed the Q_OBJECT from class definitions if the class contains neither signals nor slots, nor makes use of .ui files. This went well in most cases, but in a few cases led to segfaults.

      Is it normal and expected behavior that missing Q_OBJECT macro is not detected at compile or link time, but corrupts the runtime?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @Joachim-W said in Segfault after removal of Q_OBJECT macro - what "other services" may fail:

      Is it normal and expected behavior that missing Q_OBJECT macro is not detected at compile or link time, but corrupts the runtime?

      Yes - how should e.g. the meta object system know something about if a custom class has a Q_OBJECT macro or not?

      All this won't work: https://doc.qt.io/qt-6/qmetaobject.html and also see https://doc.qt.io/qt-6/qobject.html#qobject_cast which is a common usecase for a QObject derived class (but it will fail during compile time when the class to cast to has no Q_OBJECT)

      /edit: and when there is a segfault you should use a debugger to see where it crashes.

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

      J 2 Replies Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Joachim-W said in Segfault after removal of Q_OBJECT macro - what "other services" may fail:

        Is it normal and expected behavior that missing Q_OBJECT macro is not detected at compile or link time, but corrupts the runtime?

        Yes - how should e.g. the meta object system know something about if a custom class has a Q_OBJECT macro or not?

        All this won't work: https://doc.qt.io/qt-6/qmetaobject.html and also see https://doc.qt.io/qt-6/qobject.html#qobject_cast which is a common usecase for a QObject derived class (but it will fail during compile time when the class to cast to has no Q_OBJECT)

        /edit: and when there is a segfault you should use a debugger to see where it crashes.

        J Offline
        J Offline
        Joachim W
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        From the QMetaObject doc: »This class is not normally required for application programming«

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @Joachim-W said in Segfault after removal of Q_OBJECT macro - what "other services" may fail:

          Is it normal and expected behavior that missing Q_OBJECT macro is not detected at compile or link time, but corrupts the runtime?

          Yes - how should e.g. the meta object system know something about if a custom class has a Q_OBJECT macro or not?

          All this won't work: https://doc.qt.io/qt-6/qmetaobject.html and also see https://doc.qt.io/qt-6/qobject.html#qobject_cast which is a common usecase for a QObject derived class (but it will fail during compile time when the class to cast to has no Q_OBJECT)

          /edit: and when there is a segfault you should use a debugger to see where it crashes.

          J Offline
          J Offline
          Joachim W
          wrote on last edited by
          #4

          @Christian-Ehrlicher

          https://doc.qt.io/qt-6/qobject.html#qobject_cast

          Thanks. This is an excellent hint. There are indeed some qobject_cast in our code, in close vicinity to the classes that did not suffer Q_OBJECT to be removed.

          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