[Solved] Connecting qml signal with arguments from other qml file to qt slot
-
Seconda.qml
@
Rectangle {
signal signal_return();
signal signal_avanti(string titolo, string argomento);width: lunghezza; height: altezza FinestraDelPensiero { id: finestra_pensiero_img anchors.fill: parent visible: false z: 1 }
[...]
}
@FinestraDelPensiero.qml
@
import QtQuick 1.0Rectangle {
property int lunghezza: 1200;
property int altezza: 800;
property string testo: "Inserire: [Lingua d' Origine][Spazio][Lingua Finale]"width: lunghezza height: altezza id: finestra Image { id: image1 x: 0 y: 204 z: 3 source: "Avviso.png" } Image { id: image4 x: 302 y: 342 width: 450 height: 155 source: "v.png" MouseArea { id: mouse_area1 anchors.fill: parent onClicked: signal_avanti(testo, text_edit1.text) } } Image { id: image3 x: 752 y: 342 width: 450 height: 155 source: "x.png" MouseArea { id: mouse_area2 anchors.fill: parent onClicked: finestra.visible = true } } Image { id: image5 x: 192 y: 89 width: 1095 height: 248 scale: 0.8 source: "alert.png" Text { id: text1 x: 215 y: 48 text: testo font.bold: true anchors.verticalCenterOffset: -49 anchors.verticalCenter: parent.verticalCenter font.pixelSize: 32 } TextEdit { id: text_edit1 x: 257 y: 149 width: 80 height: 20 text: "" font.pixelSize: 35 focus: true } }
}
@Seconda.cpp
@
Seconda::Seconda(const QString creanuovasezione, QWidget *parent) :
QWidget(parent)
{
view = new QDeclarativeView(this);
view->setSource(QUrl::fromLocalFile("qml/HUVWoerterSZErinnern/Seconda.qml"));
//impostando le proprietà: altezza, larghezza e nuova parola
QObject *objview = view->rootObject();if(creanuovasezione.contains("Nuovo")) { objview->setProperty("inseriscinuovaparola_visibile", QVariant::fromValue(true)); } else { objview->setProperty("inseriscinuovaparola_visibile", QVariant::fromValue(false)); objview->setProperty("currentlingue", QVariant::fromValue(creanuovasezione)); } objview->setProperty("lunghezza", QVariant::fromValue(QApplication::desktop()->geometry().width())); objview->setProperty("altezza", QVariant::fromValue(QApplication::desktop()->geometry().height())); //END impostando le proprietà: altezza, larghezza e nuova parola connect(objview, SIGNAL(signal_avanti(QString, QString)), this, SLOT(createOrDeleteNewSection(const QString, QString))); //here the error connect(objview, SIGNAL(signal_return()), this, SLOT(openPrimaSchermata())); view->show(); this->showMaximized();
}
@how to connect the signal from FinestraDelPensiero (2nd snippet), that is used in the first snippet, to qt (3rd snippet)?
-
Expose cpp as a "context property":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#embedding-c-objects-into-qml-components say Engine. Now create a "Connections":http://doc.qt.nokia.com/latest/qml-connections.html element in Seconda.qml which is connected to the signal of interest and call the Engine slot.