Results 1 to 14 of 14

Thread: Direct connection in QML

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Direct connection in QML

    You have to implement your own element, say DirectConnections.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:


  3. #2
    Join Date
    Feb 2013
    Location
    Prague
    Posts
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Direct connection in QML

    OK, let say I have implemented my DirectConnections object. Now I also have object called Sender which emits signal called signal. And I have object called Receiver with slot called slot(). All three objects are exposed by my QML plugin called CustomPlugin.
    The QML would look like this:
    Qt Code:
    1. import CustomPlugin 1.0
    2. Sender {
    3. id: sender
    4. }
    5. Receiver {
    6. id: receiver
    7. }
    8. DirectConnections {
    9. target: receiver
    10. NOW HOW DO I CREATE CONNECTION BETWEEN onSignal and receiver.slot()
    11. }
    To copy to clipboard, switch view to plain text mode 

    The question is hidden in the code above. What shloud I do to implement such a class which would understand this: onSignal: receiver.slot() ?
    I know you can do it with Connections object. But this object is part of QML language which parses "signal: slot" notation in a special way.
    It would be brilliant if I could have custom object which keeps the same notation as Connection object. But how to implement it. Could you provide few lines of code which would illustrate it?

  4. The following user says thank you to mfojtak for this useful post:


  5. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Direct connection in QML

    For example:

    javascript Code:
    1. DirectConnections {
    2. source: sender.signal
    3. target: receiver.slot
    4. }
    To copy to clipboard, switch view to plain text mode 

    I'm not sure how to access the signal and the slot itself from the C++ side. If you can't find a way to do it, you can always use separate properties for the signal and slot signatures (as strings) that you will then use in the backend.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Direct connection in QML

    More likely having two properties of type QObject* and two properties of type QString.
    Once all four properties are set, code is triggered that does
    1) lookup of slot and signal through QMetaObject
    2) call connect with the two objects and the retrieved signal and slot signatures

    Cheers,
    _


    Added after 8 minutes:


    Ok, I have to say I don't understand the problem.

    I get DirectConnection behavior in a simple test application

    Qt Code:
    1. #ifndef TIMER_H
    2. #define TIMER_H
    3.  
    4. #include <QObject>
    5.  
    6. #include <QtQuick>
    7.  
    8. class QTimer;
    9.  
    10. class Timer : public QObject
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit Timer( QObject* parent = 0 );
    16.  
    17. signals:
    18. void timeout();
    19.  
    20. private:
    21. QTimer* m_timer;
    22.  
    23. private slots:
    24. void onInternalTimeout();
    25. };
    26.  
    27. #endif // TIMER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "timer.h"
    2.  
    3. #include <QDebug>
    4. #include <QTimer>
    5.  
    6. Timer::Timer( QObject* parent )
    7. : QObject( parent ),
    8. m_timer( new QTimer( this ) )
    9. {
    10. m_timer->setInterval( 1000 );
    11. connect(m_timer, SIGNAL(timeout()), this, SLOT(onInternalTimeout()));
    12. m_timer->start();
    13. }
    14.  
    15. void Timer::onInternalTimeout()
    16. {
    17. qDebug() << Q_FUNC_INFO;
    18. emit timeout();
    19. qDebug() << "emit timeout() returned";
    20. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. import QtQuick 2.0
    2. import CustomComponents 1.0
    3.  
    4. Timer {
    5. id: timer
    6. onTimeout: console.log( "onTimeout in QML" )
    7. }
    To copy to clipboard, switch view to plain text mode 

    Obviously exporting the Timer class with qmlRegisterType in "CustomComponents" version 1.0

    Output is
    Qt Code:
    1. void Timer::onInternalTimeout()
    2. onTimeout in QML
    3. emit timeout() returned
    To copy to clipboard, switch view to plain text mode 

    So emit returns after the "QML slot" has been called. AKA DirectConnection

    Cheers,
    _
    Last edited by anda_skoa; 12th March 2013 at 17:58.

  7. The following user says thank you to anda_skoa for this useful post:


  8. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Direct connection in QML

    Quote Originally Posted by anda_skoa View Post
    More likely having two properties of type QObject* and two properties of type QString.
    Yes, that's what I mean in the last paragraph of my previous post.

    Ok, I have to say I don't understand the problem.

    I get DirectConnection behavior in a simple test application
    I think OP wants a direct connection between objects living in different threads which is a Bad Thing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:


Similar Threads

  1. Direct QwtPlot painting
    By ssample in forum Qwt
    Replies: 1
    Last Post: 23rd January 2013, 06:41
  2. Replies: 0
    Last Post: 11th November 2011, 19:18
  3. Replies: 1
    Last Post: 2nd April 2010, 06:42
  4. Qt + WINAPI + direct painting
    By JovianGhost in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2010, 05:10
  5. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.