Introduction to Qt / QML (Part 42) - Custom Signals and Slots

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ม.ค. 2025

ความคิดเห็น • 12

  • @RifinTidHamar
    @RifinTidHamar 3 ปีที่แล้ว

    You've saved my grade. Thank you.

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว +1

      You're very welcome!

  • @maiz7056
    @maiz7056 ปีที่แล้ว

    I don't believe there was any explanation of QML in the video.
    I need to signal a value change from one "Item" to another. I've followed the documentation on the QT website, but it doesn't seem to work. I can signal the value change within the same "Item", but not to another. Do you have any guidance? Thank you.

    • @KDABtv
      @KDABtv  ปีที่แล้ว

      Hi!
      This video deals with the signal and slot mechanism of Qt Core, which is used by QML and is important for advanced QML use cases. If you want to create connections, or bindings, on the QML level, consider this video th-cam.com/video/2rtz9vkuxio/w-d-xo.html .

  • @francescoclerico8106
    @francescoclerico8106 3 ปีที่แล้ว

    Hi, How can I declare signal from interface class, later implement it in another subclass and connect to slot? I found:
    connect(dynamic_cast(obj_typeof_interface), SIGNAL(signal), this, SLOT(slot)) but doesn't work...

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว +1

      Hi Francesco!
      Qt's signals and slots don't go well with pure interface classes. Instead, consider if your interface could inherit from QObject itself, you can properly declare the signal on the interface. This is basically what Qt does: it uses "fat" interfaces that are called QAbstract. Note that when using multiple inheritance, as is often done with interfaces, you have to be quite careful. Avoid the dreaded diamond of death, and make sure the QObject (-derived) type is first in the list.
      You can also use a pure virtual method in your interface and only declare that as a signal in the class where you "implement" it. By declaring it as a signal (which you can do with override and all), moc will provide the implementation for you. That does mean you cannot connect to the signal using the pointer-to-memberfunction syntax, but the syntax you gave will work then. In general, we do not recommend you use the old SIGNAL/SLOT syntax in new code though.
      We hope this is helpful to you! If you have any questions, don't hesitate to ask you us.

  • @vinothrajendran628
    @vinothrajendran628 3 ปีที่แล้ว

    Hi thanks for the good video, i need a clarification
    How does connect mechanism works if Q_OBJECT macro is not there in class declaration file ? How slot function is getting called on QTimer's timeout ?
    As per my understanding , we need the index of slot for the connect mechanism to work, which can be read only via MOC files.

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว

      Hi Vinoth! No, for the Qt-5 syntax we don't need the Q_OBJECT macro to be there. That is possible because the call is made using the pointer-to-memberfunction syntax. No introspection of the slot is needed for this to work, and the method doesn't even to be marked as a slot (though it is good practice to do so).

    • @vinothrajendran628
      @vinothrajendran628 3 ปีที่แล้ว

      @@KDABtv , Thanks for the explanation. Is there any document, where i could read about how connection mechanism works in Qt5 ?
      General Question: Does Qt5Core.dll contains moc file for all Qt Core related class(e.g. QTimer) ?

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว

      @@vinothrajendran628 I'm not sure if there is specific documentation on how it is implemented, but a good technique is to start a debugger, then set a breakpoint in a slot of yours (which would be connected to, say your QTimer), then when the break point is hit, simply travel up in your debugger to the point where the signal is emitted, and then go step by step down from there again. That will show you how it works behind the scene.

  • @jeromelaclavere2977
    @jeromelaclavere2977 3 ปีที่แล้ว

    Hi,
    at 3:06, while the "sorry again", you are really good. But it's probably not the first time you make this joke, is it ? =)

  • @PhilWatson-e2q
    @PhilWatson-e2q 7 หลายเดือนก่อน

    I am so guilty of calling my slots by what triggers them not what they do!!!