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. Correct syntax to register object reference using qRegisterMetaType?
Forum Updated to NodeBB v4.3 + New Features

Correct syntax to register object reference using qRegisterMetaType?

Scheduled Pinned Locked Moved Solved General and Desktop
34 Posts 7 Posters 6.4k 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.
  • K kshegunov
    6 Jan 2021, 15:55

    @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

    I want to pass by reference because my understanding of passing by reference is that it is far less costly on stack space. A QJsonObject can be very large.

    Your understanding is irrelevant in this case. You were told it isn't possible with a queued connection, and it still isn't, and it is not going to be, no matter how much we argue about it. The warning is there for a reason - to warn you that you have a serious bug in your code. You can either use a direct connection and suffer the inevitable consequences of that, or use const QJsonObject &/QJsonObject for your signal arguments.

    S Offline
    S Offline
    SPlatten
    wrote on 6 Jan 2021, 16:36 last edited by
    #13

    @kshegunov , I am using const QJsonObject& for my signal arguments, these are working, the only thing that is displayed in the Application Output is the message I've raised. I'm not experience any other problems, crashes or bugs.

    Kind Regards,
    Sy

    J S 2 Replies Last reply 6 Jan 2021, 16:49
    0
    • S SPlatten
      6 Jan 2021, 16:36

      @kshegunov , I am using const QJsonObject& for my signal arguments, these are working, the only thing that is displayed in the Application Output is the message I've raised. I'm not experience any other problems, crashes or bugs.

      J Offline
      J Offline
      JonB
      wrote on 6 Jan 2021, 16:49 last edited by
      #14

      @SPlatten
      The signal argument type is "OK", insofar as it would work OK with non-cross-thread direct connection connect()s. But the problem is that you are trying to use it when you need a queued connection. That is why you get the error message on the QObject::connect statement.

      S 1 Reply Last reply 6 Jan 2021, 17:51
      1
      • J JonB
        6 Jan 2021, 16:49

        @SPlatten
        The signal argument type is "OK", insofar as it would work OK with non-cross-thread direct connection connect()s. But the problem is that you are trying to use it when you need a queued connection. That is why you get the error message on the QObject::connect statement.

        S Offline
        S Offline
        SPlatten
        wrote on 6 Jan 2021, 17:51 last edited by
        #15

        @JonB , thank you, I'll take a look.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • S SPlatten
          6 Jan 2021, 16:36

          @kshegunov , I am using const QJsonObject& for my signal arguments, these are working, the only thing that is displayed in the Application Output is the message I've raised. I'm not experience any other problems, crashes or bugs.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Jan 2021, 18:01 last edited by
          #16

          @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

          @kshegunov , I am using const QJsonObject& for my signal arguments, these are working, the only thing that is displayed in the Application Output is the message I've raised. I'm not experience any other problems, crashes or bugs.

          For the slots as well ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 6 Jan 2021, 18:20
          2
          • S SGaist
            6 Jan 2021, 18:01

            @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

            @kshegunov , I am using const QJsonObject& for my signal arguments, these are working, the only thing that is displayed in the Application Output is the message I've raised. I'm not experience any other problems, crashes or bugs.

            For the slots as well ?

            S Offline
            S Offline
            SPlatten
            wrote on 6 Jan 2021, 18:20 last edited by
            #17

            @SGaist Of course.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SPlatten
              wrote on 6 Jan 2021, 18:23 last edited by
              #18

              Ok, I've now got rid of the warning, by going through all the QObject::connect calls and only using Qt::DirectionConnection where the signal and slot pointers are the same.

              Kind Regards,
              Sy

              J 1 Reply Last reply 6 Jan 2021, 18:29
              0
              • S SPlatten
                6 Jan 2021, 18:23

                Ok, I've now got rid of the warning, by going through all the QObject::connect calls and only using Qt::DirectionConnection where the signal and slot pointers are the same.

                J Offline
                J Offline
                JonB
                wrote on 6 Jan 2021, 18:29 last edited by
                #19

                @SPlatten
                A lot of your questions are about threads. Are your connect()s' senders/receivers never in separate threads?

                S 1 Reply Last reply 6 Jan 2021, 18:30
                0
                • J JonB
                  6 Jan 2021, 18:29

                  @SPlatten
                  A lot of your questions are about threads. Are your connect()s' senders/receivers never in separate threads?

                  S Offline
                  S Offline
                  SPlatten
                  wrote on 6 Jan 2021, 18:30 last edited by
                  #20

                  @JonB , not for the ones where I've used Qt::DirectConnection

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  1
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 6 Jan 2021, 18:38 last edited by
                    #21

                    @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                    not for the ones where I've used Qt::DirectConnection

                    Then it's useless since then Qt::AutoConnection evaluates to Qt::DirectConnection. Specifying a connection type is not needed in most of the cases.

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

                    S 1 Reply Last reply 6 Jan 2021, 18:45
                    0
                    • C Christian Ehrlicher
                      6 Jan 2021, 18:38

                      @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                      not for the ones where I've used Qt::DirectConnection

                      Then it's useless since then Qt::AutoConnection evaluates to Qt::DirectConnection. Specifying a connection type is not needed in most of the cases.

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 6 Jan 2021, 18:45 last edited by
                      #22

                      @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                      Kind Regards,
                      Sy

                      S C K 3 Replies Last reply 6 Jan 2021, 18:46
                      0
                      • S SPlatten
                        6 Jan 2021, 18:45

                        @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 6 Jan 2021, 18:46 last edited by
                        #23

                        @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                        @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                        For that a minimal compilable example would be needed.

                        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
                        • S SPlatten
                          6 Jan 2021, 18:45

                          @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                          C Offline
                          C Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 6 Jan 2021, 18:50 last edited by
                          #24

                          @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                          so perhaps this is something that needs looking at?

                          This means that there is a thread context switch somewhere even you tell us it isn't.

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

                          1 Reply Last reply
                          2
                          • S SPlatten
                            6 Jan 2021, 18:45

                            @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                            K Offline
                            K Offline
                            kshegunov
                            Moderators
                            wrote on 6 Jan 2021, 19:34 last edited by
                            #25

                            @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                            @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                            Run with QT_FATAL_WARNINGS=1 as an environment variable and extract the stack trace, then you will have leveraged your debugger to show you exactly where you're passing a reference between threads.

                            Read and abide by the Qt Code of Conduct

                            S 1 Reply Last reply 6 Jan 2021, 20:11
                            2
                            • K kshegunov
                              6 Jan 2021, 19:34

                              @SPlatten said in Correct syntax to register object reference using qRegisterMetaType?:

                              @Christian-Ehrlicher , Well that's the only change I'm implemented and now there is no message, so perhaps this is something that needs looking at?

                              Run with QT_FATAL_WARNINGS=1 as an environment variable and extract the stack trace, then you will have leveraged your debugger to show you exactly where you're passing a reference between threads.

                              S Offline
                              S Offline
                              SPlatten
                              wrote on 6 Jan 2021, 20:11 last edited by
                              #26

                              @kshegunov said in Correct syntax to register object reference using qRegisterMetaType?:

                              QT_FATAL_WARNINGS=1

                              I've opened both .pro files and added that line, then cleaned and rebuilt, the applications have been running for several minutes, nothing to report, no issues.

                              Kind Regards,
                              Sy

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 6 Jan 2021, 20:15 last edited by
                                #27

                                It's an environnement variable, not a define.

                                You have to set it in the Run tab of the Project panel.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                S 1 Reply Last reply 6 Jan 2021, 20:16
                                1
                                • S SGaist
                                  6 Jan 2021, 20:15

                                  It's an environnement variable, not a define.

                                  You have to set it in the Run tab of the Project panel.

                                  S Offline
                                  S Offline
                                  SPlatten
                                  wrote on 6 Jan 2021, 20:16 last edited by
                                  #28

                                  @SGaist , Yes, just googled it and then added as environment variable:

                                  export QT_FATAL_WARNINGS=1
                                  

                                  Then restarted, same, not seeing anything additional.

                                  Kind Regards,
                                  Sy

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 6 Jan 2021, 20:18 last edited by
                                    #29

                                    Restarted what ?
                                    How are you currently running your application ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    S 1 Reply Last reply 7 Jan 2021, 07:50
                                    1
                                    • S SGaist
                                      6 Jan 2021, 20:18

                                      Restarted what ?
                                      How are you currently running your application ?

                                      S Offline
                                      S Offline
                                      SPlatten
                                      wrote on 7 Jan 2021, 07:50 last edited by
                                      #30

                                      @SGaist , I launch the processes with Qt Creator in debug mode, using two separate instances of Qt Creator.

                                      Kind Regards,
                                      Sy

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 7 Jan 2021, 08:33 last edited by SGaist 1 Jul 2021, 08:33
                                        #31

                                        Did you check the environment variables in the Run part of the Project Panel to ensure it's properly set ?

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        S 1 Reply Last reply 8 Jan 2021, 07:10
                                        1
                                        • S SGaist
                                          7 Jan 2021, 08:33

                                          Did you check the environment variables in the Run part of the Project Panel to ensure it's properly set ?

                                          S Offline
                                          S Offline
                                          SPlatten
                                          wrote on 8 Jan 2021, 07:10 last edited by
                                          #32

                                          @SGaist , I checked in a terminal, I don't know how or where to "Run part of the Project Panel" ?

                                          Kind Regards,
                                          Sy

                                          jsulmJ 1 Reply Last reply 8 Jan 2021, 07:14
                                          0

                                          22/34

                                          6 Jan 2021, 18:45

                                          • Login

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