Hi,
I see data in application output of Qt Creator, but I can not bind this data to text control.
Please guide me.
Thanks
main.cpp:
int main(int argc, char *argv[])
{
QQmlApplicationEngine engine;
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
MySerialPort iSerialPort;
iSerialPort.moveToThread(iTH);
iSerialPort.openSerialPort();
iTH->start();
return app.exec();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
MySerialPort iSerialPort;
QThread * iTH = new QThread;
iSerialPort.moveToThread(iTH);
iSerialPort.openSerialPort();
iTH->start();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
myserialport.cpp:
void MySerialPort::readData()
{
qDebug() << data;
QQmlEngine engine;
QQmlComponent component
(&engine,
QUrl("qrc:MyItem.qml"));
QObject *object
= component.
create();
object->setProperty("text1Text",data);
}
void MySerialPort::readData()
{
QByteArray data = serial->readAll();
qDebug() << data;
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:MyItem.qml"));
QObject *object = component.create();
object->setProperty("text1Text",data);
}
To copy to clipboard, switch view to plain text mode
MyItem.qml:
import QtQuick 2.0
import QtQuick.Controls 1.2
Item {
id: item1
width: 400
height: 400
property alias text1Text: text1.text
Text {
id: text1
width: 400
height: 29
color: "red"
text: "This text should change..."
font.pixelSize: 12
}
}
import QtQuick 2.0
import QtQuick.Controls 1.2
Item {
id: item1
width: 400
height: 400
property alias text1Text: text1.text
Text {
id: text1
width: 400
height: 29
color: "red"
text: "This text should change..."
font.pixelSize: 12
}
}
To copy to clipboard, switch view to plain text mode
main.qml:
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick 2.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MyItem{
}
}
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick 2.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MyItem{
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks