PDA

View Full Version : Stage active event from QML file



AbinaThomas
7th September 2012, 07:35
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 :


QDeclarativeView *view = new QDeclarativeView();
view->setSource(QUrl::fromLocalFile("base.qml"));
Qmlview = view;
QObject *item = view->rootObject();
QObject::connect(item,SIGNAL(qmlSignal(QString)),t his,SLOT(cppSlot(QString)));
Qmlview->show();


and in the QML side i wrote:


Rectangle {
id : item1
width: 400
height: 400
color: "#d5b9b9"

signal qmlSignal(string msg)
Component.onCompleted:
{

item1.qmlSignal("string msg")
}

}


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...

wysota
8th September 2012, 06:05
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.