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. Access to signal arguments in qt_metacall?
Forum Updated to NodeBB v4.3 + New Features

Access to signal arguments in qt_metacall?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 5.0k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    What do you mean by custom qt_metacall ? Are you trying to do the job of moc yourself ?

    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
    • J Offline
      J Offline
      JohnAC
      wrote on last edited by
      #3

      Possibly, I'm not familiar with moc (I'm new to Qt). I'm trying to make dynamic slots/signals as part of a Qt binding.

      I've defined a QObject that doesn't use the Q_OBJECT macro so I can define the meta methods myself.

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

        Then I would recommend that you first get familiar with it. moc (the meta object compiler) takes a QObject header as input and generates the code you are trying to write by hand

        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
        • J Offline
          J Offline
          JohnAC
          wrote on last edited by
          #5

          Which is done at compile time no? I'm trying to make slots and signals dynamic, ie: defined at runtime.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #6

            Signals and Slots always are dynamic - in the sense that you setup the connections between objects at runtime by using connect(). But which Slots or Signals an object has is defined by its class. And in C++ the class is fixed at compile time (this is not specific to Qt at all). The only thing that is specific to Qt is that you need to to process your header files with MOC and compile MOC's output into your binary. This makes the Signals and Slot "magic" work.

            Recommended reading:
            http://qt-project.org/doc/qt-4.8/moc.html

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JohnAC
              wrote on last edited by
              #7

              And I'm not wanting to define slots/signals at compile time in this case, which is why my code is using QMetaObject directly to connect and emit signals.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MuldeR
                wrote on last edited by
                #8

                [quote author="JohnAC" date="1398720758"]And I'm not wanting to define slots/signals at compile time[/quote]

                Can you explain why this is required?

                [quote author="JohnAC" date="1398720758"]my code is using QMetaObject directly to connect and emit signals[/quote]

                Connections between Signals and Slots are always set up at run time, using QObject:connect(). Also signals are always emitted at runtime, using the "emit" keyword. What is fixed at compile-time is which Signals and/or Slots a specific class offers. And that's no different from "regular" member functions.

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JohnAC
                  wrote on last edited by
                  #9

                  bq. Can you explain why this is required?

                  Because the slots and signals being used aren't known at compile time. I'm binding to language (C#) that plainly requires the capability of defining the slots and signals at runtime.

                  I've been following this to get as far as I have: http://doc.qt.digia.com/qq/qq16-dynamicqobject.html

                  And it mostly works, I just can't access the arguments being passed through within my slot handling code.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on last edited by
                    #10

                    [quote author="JohnAC" date="1398721473"]bq. Can you explain why this is required?

                    Because the slots and signals being used aren't known at compile time.[/quote]

                    And they don't have to. You can have an arbitrary number of Signals and/or Slots in your classes and still only connect to a small subset of those at runtime. That's perfectly normal. Most of the original Qt classes will have lots of Signals and Slots that you'll never use in your application at runtime.

                    [quote author="JohnAC" date="1398721473"]I'm binding to language (C#) that plainly requires the capability of defining the slots and signals at runtime.[/quote]

                    I'm not so sure about this yet ;-)

                    My experience in C# is a bit limited, but AFAIK classes in C# are also fixed at compile-time, i.e. adding a method to a class at runtime is not possible in C# either (unlike e.g. Python). So when/why exactly do you need to add a Signal or Slot to your C++ class at runtime? Can you give an example?

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JohnAC
                      wrote on last edited by
                      #11

                      Sigh...

                      You're right about C# in a way - classes are immutable, you can't add or remove members to/from types at runtime.

                      C# uses Qt through a glue library. This glue library has no knowledge of the C# project at all and, thus, cannot use moc to compile signal and slot definitions.

                      The way the C# code is working is by using a type initalizer (not sure if C++ has these). It's basically a static constructor that's invoked when a Type is first encountered at runtime. Anyway, the initalizer will then perform what is analogous to moc - it will read metadata from the class definition and instruct the glue library to create a dynamic signal/slot object that can be used for connections later.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MuldeR
                        wrote on last edited by
                        #12

                        Ah, it becomes more clear now. But wouldn't it be possible to have some kind of native "proxy" class on the C++ side that acts on behalf of the managed C# class? The native class, derived from QObject, could then be processed by MOC as usual, establish connections via QObject::connect() and so on. Finally, that "proxy" class could be "wrapped for use by C#":http://msdn.microsoft.com/en-us/library/ms235281.aspx.

                        My OpenSource software at: http://muldersoft.com/

                        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                        Go visit the coop: http://youtu.be/Jay...

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          JohnAC
                          wrote on last edited by
                          #13

                          Yes that would be possible but a 1:1 relationship betwen C# and C++ types is very undesirable. Each time I, or another developer, wanted to define a type to interop with Qt in this way would also have to write a C++ class to go with it, compile the library with the definitions etc.

                          Anyway, I've been talking with thiago on IRC and we discovered that the issue I'm running into is due to the sender and receiver being on different threads and the queued emit code not having enough information regarding the arguments being passed.

                          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