Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Be sure of the creation of an object
Qt 6.11 is out! See what's new in the release blog

Be sure of the creation of an object

Scheduled Pinned Locked Moved Mobile and Embedded
qt5.4.1qobject
10 Posts 4 Posters 5.2k Views 4 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.
  • N Offline
    N Offline
    NGV1
    wrote on last edited by NGV1
    #1

    Hello,

    Is there a way to be sure of the creation of an object ?
    for example, if I write :

    QLabel *lbl = new QLabel("Hello world");
    

    How can I be sure that the label is created ? Is there any signal , or something ?

    K JKSHJ 2 Replies Last reply
    0
    • N NGV1

      Hello,

      Is there a way to be sure of the creation of an object ?
      for example, if I write :

      QLabel *lbl = new QLabel("Hello world");
      

      How can I be sure that the label is created ? Is there any signal , or something ?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @NGV1

      Simply test the pointer. It should be zero when the object is not created.

      Vote the answer(s) that helped you to solve your issue(s)

      JKSHJ 1 Reply Last reply
      0
      • K koahnig

        @NGV1

        Simply test the pointer. It should be zero when the object is not created.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @koahnig said:

        @NGV1

        Simply test the pointer. It should be zero when the object is not created.

        You would probably get an exception too: http://stackoverflow.com/questions/6833143/how-to-check-memory-allocation-failures-with-new-operator

        @NGV1 said:

        How can I be sure that the label is created ? Is there any signal , or something ?

        What will you do if the label fails to be created?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NGV1
          wrote on last edited by
          #4

          Thanks for answering,
          @JKSH
          If it fail, either I display an error or I try it again,

          JKSHJ 1 Reply Last reply
          0
          • N NGV1

            Thanks for answering,
            @JKSH
            If it fail, either I display an error or I try it again,

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            You're welcome :)

            @NGV1 said:

            If it fail, either I display an error or I try it again,

            I have never seen it fail on my PCs.

            Anyway, the only reason I can think of for failure is when you use up all your RAM. How will you display an error when you don't have any RAM left?

            Also, if it fails the first time, why would it succeed when you try again?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NGV1
              wrote on last edited by
              #6

              In fact, it's just to know if it's creating or if it's created, and after a timeout, I consider that it fail, so it's not necessarily a RAM issue.
              Moreover, while I didn't create this object, I don't try to create the following.

              Thanks for the link, I'll study it !

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

                Hi,

                I must say that's is pretty strange concept, how are you implementing it ? What is your use case ?

                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
                • N NGV1

                  Hello,

                  Is there a way to be sure of the creation of an object ?
                  for example, if I write :

                  QLabel *lbl = new QLabel("Hello world");
                  

                  How can I be sure that the label is created ? Is there any signal , or something ?

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @NGV1 said:

                  In fact, it's just to know if it's creating or if it's created, and after a timeout, I consider that it fail

                  Um... new QLabel("Hello world"); cannot possibly timeout. It will either instantly succeed or instantly fail.

                  You cannot check if an object is "in the middle of creation".

                  Where did you learn these ideas from?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    koahnig
                    wrote on last edited by
                    #9

                    If this is not a completely hypothetical discussion and you see some sort of a timeout, it sounds more like a daggling pointer. When you allocate memory as you do in the little example and it goes out of focus, the pointer will be overwritten eventually on the stack.

                    Vote the answer(s) that helped you to solve your issue(s)

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      NGV1
                      wrote on last edited by
                      #10

                      Thanks every body,
                      I'm developing, a Bluetooth application. The bluetooth trames reception should manage the display, and I would like to be sure that nothing is forgotten. So when I receive a Bluetooth trame (after a request), I send an acknowledgement with checksum, and I send an other request when I finish the treatment of this trame. That's why I would like to be sure that the objects are created, to avoid error because of the modification of an object that does not exist.

                      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