Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Confused about how connect is passing argument to a function

Confused about how connect is passing argument to a function

Scheduled Pinned Locked Moved Solved Language Bindings
10 Posts 5 Posters 1.4k 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.
  • T Offline
    T Offline
    TenG
    wrote on 11 Mar 2021, 23:05 last edited by
    #1

    I'm stilling a novice at Qt, and am totally at a loss with the following.

    I have this function:

    void OAuth2Manager::onAuthorizeWithBrowser(const QUrl &url)
    {
       qDebug() << "OAuth2Manager::onAuthorizeWithBrowser:" << url;
    }
    

    The function is only referenced as follows:

    _oAuth2 = new QOAuth2AuthorizationCodeFlow( this);
    
    connect (_oAuth2,
             &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser,
             this,
             &OAuth2Manager::onAuthorizeWithBrowser);
    

    How does it get the function get the url argument passed in?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TenG
      wrote on 13 Mar 2021, 18:01 last edited by
      #8

      Although I'm somewhat still confused about the inner working of the slot/signal/emit and how it works with such argument passing, I managed to the functional problem that was causing me to delve into these murky waters.

      For anyone interested see this post for the details:

      https://forum.qt.io/topic/124685/qabstractoauth2-missing-access_type-and-approval_prompt

      As for the matter to hand here, I'm assuming that there emit is buried with the QOAuth2AuthorizationCodeFlow class somewhere which is why I cannot see it.

      I'm closing this as answered.

      K 1 Reply Last reply 15 Mar 2021, 07:37
      0
      • 6 Offline
        6 Offline
        6thC
        wrote on 11 Mar 2021, 23:33 last edited by
        #2

        from the function sig. , see functor-based connection

        In contrast, functor-based connections are checked by the compiler. The compiler catches errors at compile-time, enables implicit conversions between compatible types, and recognizes different names of the same type.

        T 1 Reply Last reply 11 Mar 2021, 23:51
        0
        • 6 6thC
          11 Mar 2021, 23:33

          from the function sig. , see functor-based connection

          In contrast, functor-based connections are checked by the compiler. The compiler catches errors at compile-time, enables implicit conversions between compatible types, and recognizes different names of the same type.

          T Offline
          T Offline
          TenG
          wrote on 11 Mar 2021, 23:51 last edited by
          #3

          @6thC Thank you. If I understand you correctly the code above should cause a compilation error, but it doesn't. The code compiles, builds and runs! My issue is I need to make a change (to the url value) but I cannot seem to figure out where this value is set, comes from or how it ends up in this function. Although I am a novice at Qt, I do know my way around programming languages so I think I am drowning in some esoteric waters here.

          E 1 Reply Last reply 12 Mar 2021, 00:12
          0
          • T TenG
            11 Mar 2021, 23:51

            @6thC Thank you. If I understand you correctly the code above should cause a compilation error, but it doesn't. The code compiles, builds and runs! My issue is I need to make a change (to the url value) but I cannot seem to figure out where this value is set, comes from or how it ends up in this function. Although I am a novice at Qt, I do know my way around programming languages so I think I am drowning in some esoteric waters here.

            E Offline
            E Offline
            eyllanesc
            wrote on 12 Mar 2021, 00:12 last edited by
            #4

            @TenG That url is emitted by _oAuth2 through the authorizeWithBrowser signal, that is, internally that class processes the requests and when it gets the url then it sends it through that signal. I recommend you read https://doc.qt.io/qt-5/signalsandslots.html. I think you have an XY problem.

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            T 1 Reply Last reply 12 Mar 2021, 10:41
            1
            • E eyllanesc
              12 Mar 2021, 00:12

              @TenG That url is emitted by _oAuth2 through the authorizeWithBrowser signal, that is, internally that class processes the requests and when it gets the url then it sends it through that signal. I recommend you read https://doc.qt.io/qt-5/signalsandslots.html. I think you have an XY problem.

              T Offline
              T Offline
              TenG
              wrote on 12 Mar 2021, 10:41 last edited by
              #5

              @eyllanesc Thank you. But there must be somewhere whereby something knows/is instructed to pass a variable to that function. I am having difficult trying to trace which source variable it is. I do not understand what the term XY means but I'll try reading the documentation you recommended.

              J K E 3 Replies Last reply 12 Mar 2021, 10:47
              0
              • T TenG
                12 Mar 2021, 10:41

                @eyllanesc Thank you. But there must be somewhere whereby something knows/is instructed to pass a variable to that function. I am having difficult trying to trace which source variable it is. I do not understand what the term XY means but I'll try reading the documentation you recommended.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 12 Mar 2021, 10:47 last edited by
                #6

                @TenG You need to search for the place where the signal authorizeWithBrowser is emitted, then you will know from where the value for the parameter is coming. So, simply grep in the source code for authorizeWithBrowser.

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

                1 Reply Last reply
                0
                • T TenG
                  12 Mar 2021, 10:41

                  @eyllanesc Thank you. But there must be somewhere whereby something knows/is instructed to pass a variable to that function. I am having difficult trying to trace which source variable it is. I do not understand what the term XY means but I'll try reading the documentation you recommended.

                  K Offline
                  K Offline
                  KroMignon
                  wrote on 12 Mar 2021, 10:48 last edited by
                  #7

                  @TenG said in Confused about how connect is passing argument to a function:

                  I do not understand what the term XY means but I'll try reading the documentation you recommended.

                  YX Problem: You have a problem "X", but asking to do "Y" because you are thinking this will solve your issue "X".
                  ==> Right way would be to expose the orignal problem "X".

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TenG
                    wrote on 13 Mar 2021, 18:01 last edited by
                    #8

                    Although I'm somewhat still confused about the inner working of the slot/signal/emit and how it works with such argument passing, I managed to the functional problem that was causing me to delve into these murky waters.

                    For anyone interested see this post for the details:

                    https://forum.qt.io/topic/124685/qabstractoauth2-missing-access_type-and-approval_prompt

                    As for the matter to hand here, I'm assuming that there emit is buried with the QOAuth2AuthorizationCodeFlow class somewhere which is why I cannot see it.

                    I'm closing this as answered.

                    K 1 Reply Last reply 15 Mar 2021, 07:37
                    0
                    • T TenG
                      13 Mar 2021, 18:01

                      Although I'm somewhat still confused about the inner working of the slot/signal/emit and how it works with such argument passing, I managed to the functional problem that was causing me to delve into these murky waters.

                      For anyone interested see this post for the details:

                      https://forum.qt.io/topic/124685/qabstractoauth2-missing-access_type-and-approval_prompt

                      As for the matter to hand here, I'm assuming that there emit is buried with the QOAuth2AuthorizationCodeFlow class somewhere which is why I cannot see it.

                      I'm closing this as answered.

                      K Offline
                      K Offline
                      KroMignon
                      wrote on 15 Mar 2021, 07:37 last edited by
                      #9

                      @TenG said in Confused about how connect is passing argument to a function:

                      Although I'm somewhat still confused about the inner working of the slot/signal/emit and how it works with such argument passing

                      That is bad, because signal/slot mechanism is a fundamental functionality of Qt and it is very important to understand it.
                      It is not so hard to understand:

                      • first, signals, slots and emit are code markup extension used by Qt. In fact they are defines to nothing (check qobjectdefs.h), only signals is a define to public. All signals generated function have to be public for the moc (see bellow)
                      • signals and slots are working only with C++ instances which are base on QObject or a derived class with definition of macro Q_OBJECT in his header.
                      • during compilation, each header of QObject based class in "pre-compiled" with moc (Meta-Object-Compiler ==> https://doc.qt.io/qt-5/why-moc.html). This step will generate an additional cpp file with all the "magic code" needed to handle signals/slots. This step is automatically done by QMake/CMake and the generated c++ files are also add to the final Makefile.

                      The code generated, is the code behind the signals functions which you have defined in your class header.
                      This is why the emit keyword you have added in the C++ code is not necessary, it is only for the developer to identify when a signal is emitted.

                      So emitting a signal is in fact a function call.

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1
                      • T TenG
                        12 Mar 2021, 10:41

                        @eyllanesc Thank you. But there must be somewhere whereby something knows/is instructed to pass a variable to that function. I am having difficult trying to trace which source variable it is. I do not understand what the term XY means but I'll try reading the documentation you recommended.

                        E Offline
                        E Offline
                        eyllanesc
                        wrote on 15 Mar 2021, 07:48 last edited by
                        #10

                        @TenG XY Problem: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem

                        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                        1 Reply Last reply
                        0

                        2/10

                        11 Mar 2021, 23:33

                        topic:navigator.unread, 8
                        • Login

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