I’m performing some basic test of QML and C++ source integration.
I’m using QT 6.5:
Here is my code QML:
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15
import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Input 2.15
import Qt3D.Extras 2.15
import com.myCode 1.0
Rectangle {
width: 640
height: 480
Item {
anchors.centerIn: parent
// Button to connect to server
Button {
text: "Connect"
onClicked: {
tcpClient.connectToServer("localhost", 8010)
}
}
}
// Expose TCP client object to QML
MyWindow {
id: tcpClient
}
}
My CPP code looks like this:
#include "mywindow.h"
#include "qqml.h"
#include <QTcpSocket>
MyWindow::MyWindow(QObject *parent) : QObject(parent)
{
// Implement your TCP connection code here
// Register C++ class with QML engine
qmlRegisterType<MyWindow>("com.myCode", 1, 0, "MyWindow");
}
void MyWindow::connectToTCP() {
QTcpSocket* socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()), this, SLOT(onConnected()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
connect(socket, SIGNAL(stateChanged(QTcpSocket::SocketState)), this, SLOT(onStateChanged(QTcpSocket::SocketState)));
connect(socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
socket->connectToHost("localhost", 8010);
}
If required I can add the header file and the cmake.
The source code compile fine, however as soon as I start debugging, I receive the message:
module "com.myCode" is not installed
Is there anyone that can help me?