Results 1 to 14 of 14

Thread: Direct connection in QML

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    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.

  2. The following user says thank you to anda_skoa 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.