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. How to determine QObject* is empty or not?
Forum Updated to NodeBB v4.3 + New Features

How to determine QObject* is empty or not?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.8k Views 1 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.
  • C Offline
    C Offline
    clementNg
    wrote on last edited by
    #1

    I have tried

    if(object != nullptr) {
            qDebug() << "test ";
            qDebug() << QString::fromStdString(event->source()->metaObject()->className());
    }
    

    it can enter the checking but I cannot get the className and it crashed on that line. Am I using the wrong method to determine the QObject*? Thank you.

    J.HilkJ 1 Reply Last reply
    0
    • C clementNg

      I have tried

      if(object != nullptr) {
              qDebug() << "test ";
              qDebug() << QString::fromStdString(event->source()->metaObject()->className());
      }
      

      it can enter the checking but I cannot get the className and it crashed on that line. Am I using the wrong method to determine the QObject*? Thank you.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @clementNg
      you're checking, if the object is != nullptr, but than you do not use the object but the event.

      Shouldn't you rather check if event is valid?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      C 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @clementNg
        you're checking, if the object is != nullptr, but than you do not use the object but the event.

        Shouldn't you rather check if event is valid?

        C Offline
        C Offline
        clementNg
        wrote on last edited by
        #3

        @J.Hilk
        Thank you for your reply.
        I dun know how to check the event too. Would you mind to give me some advices?

        J.HilkJ jsulmJ 2 Replies Last reply
        0
        • C clementNg

          @J.Hilk
          Thank you for your reply.
          I dun know how to check the event too. Would you mind to give me some advices?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @clementNg well, what is event ? can you show some more of your code?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Pl45m4P 1 Reply Last reply
          3
          • J.HilkJ J.Hilk

            @clementNg well, what is event ? can you show some more of your code?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @J.Hilk

            I think he's referring to this https://forum.qt.io/topic/104192/draggable-itemwidget-in-treewidget/6 and he tries to check if his dropped PushButton is valid or not.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • C clementNg

              @J.Hilk
              Thank you for your reply.
              I dun know how to check the event too. Would you mind to give me some advices?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @clementNg said in How to determine QObject* is empty or not?:

              I dun know how to check the event too

              If event is a pointer then you do it like you do for object...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3

              • Login

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