Results 1 to 2 of 2

Thread: Stage active event from QML file

  1. #1
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Stage active event from QML file

    Hi,

    I loaded a QML file from QT C++ class using QDeclarativeView object. I want a signal from QML file to CPP after it is active.
    My sample code is :
    Qt Code:
    1. QDeclarativeView *view = new QDeclarativeView();
    2. view->setSource(QUrl::fromLocalFile("base.qml"));
    3. Qmlview = view;
    4. QObject *item = view->rootObject();
    5. QObject::connect(item,SIGNAL(qmlSignal(QString)),this,SLOT(cppSlot(QString)));
    6. Qmlview->show();
    To copy to clipboard, switch view to plain text mode 

    and in the QML side i wrote:
    Qt Code:
    1. Rectangle {
    2. id : item1
    3. width: 400
    4. height: 400
    5. color: "#d5b9b9"
    6.  
    7. signal qmlSignal(string msg)
    8. Component.onCompleted:
    9. {
    10.  
    11. item1.qmlSignal("string msg")
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    but it seems that the signal will emit before the connection handler.
    Is there any event in QML which will active after "Qmlview->show();" ?

    Thanks in advance...

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

    Default Re: Stage active event from QML file

    Quote Originally Posted by AbinaThomas View Post
    but it seems that the signal will emit before the connection handler.
    How do you know that?

    Is there any event in QML which will active after "Qmlview->show();" ?
    A showing widget is being sent a showEvent. You can install an event filter to react on it. Or you can use QMetaObject::invokeMethod() with Qt::QueuedConnection to execute code once Qt enters its event loop.
    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.


Similar Threads

  1. Updating the file from outside the application how to capture the event.
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 3rd January 2012, 13:38
  2. How to make fewer errors at the stage of code writing. Part N3. QT.
    By Andrey_Karpov in forum General Discussion
    Replies: 0
    Last Post: 13th July 2011, 07:39
  3. How to set the QTIMER active only once ?
    By wter27 in forum Qt Programming
    Replies: 3
    Last Post: 28th February 2011, 09:06
  4. Qt Designer Change active .ui file || Show a second window
    By MrRump in forum Qt Tools
    Replies: 4
    Last Post: 5th June 2010, 19:57
  5. Replies: 1
    Last Post: 12th April 2010, 12:00

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.