I am trying to write some Qt C++ code that interacts with QML objects. The goal is to have strings received on a TCP socket appended to a text log on the GUI. Each time a new string is received, I run the appendText() function. I have one implementation of this currently working that uses QWidgets and a .ui file. I need to have a QML implementation that is identical. My QWidget implementation uses a textBrowser and the append function such as the following. "theString" is changing as the program runs and each change is appended, filling up the text log.
//update the text log with data received on TCP socket
void MainWindow::appendText() {
ui->textBrowser->append(theString);
}
This gives me the desired result, appending each string to the text box as they come in. The output should look like the following.
Control connection successful.
Data connection successful.
Control Packet Receieved:
1
Control Packet Receieved:
2
Control Packet Receieved:
3
Control Packet Receieved:
4
Control Packet Receieved:
1
Control Packet Receieved:
2
Control Packet Receieved:
3
Control Packet Receieved:
4
However, when doing what I believe to be the same function with a QML object with the following code...
//update the text log with data received on TCP socket
void MainWindow::appendText() {
QMetaObject::invokeMethod(textbox, "append", Qt::DirectConnection, Q_ARG(QVariant, theString));
//QQmlProperty(textbox, "text").write(theString);
}
It only appends the first two strings, and no more beyond that. The output looks like this instead.
Control connection successful.
Data connection successful.
I have looked over the documentation for invoking QML methods in C++ extensively and still haven't had any luck. Any help is appreciated. Thanks for your time.