Im am trying to make a very basic Qt application that will use C++ for the data model and QML for the GUI. To my surprise it is not easy to find a good tutorial for this, so it's very much "trial and error". This is the code I've got so far:
main.cpp:
#include <QtDeclarative>
int main(int argc, char *argv[])
{
QDeclarativeView view;
view.
setSource(QUrl::fromLocalFile("qml/myapp/main.qml"));
view.show();
QObject::connect(root,
SIGNAL(quit
()),
&app,
SLOT(quit
()));
return app.exec();
}
#include <QtDeclarative>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("qml/myapp/main.qml"));
view.show();
QObject *root = view.rootObject();
QObject::connect(root, SIGNAL(quit()), &app, SLOT(quit()));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
main.qml:
import QtQuick 1.0
Rectangle {
width: 360
height: 360
Text {
text: "Hello World"
anchors.centerIn: parent
}
signal quit()
MouseArea {
anchors.fill: parent
onClicked: {
quit();
}
}
}
import QtQuick 1.0
Rectangle {
width: 360
height: 360
Text {
text: "Hello World"
anchors.centerIn: parent
}
signal quit()
MouseArea {
anchors.fill: parent
onClicked: {
quit();
}
}
}
To copy to clipboard, switch view to plain text mode
What it does is very simple: it shows a rectangle with the text "Hello World", and when you click in the rectangle the program quits. I know that this is exactly the same as the default app that Qt Creator creates when you choose to make a new "Qt Quick Application", but my app does it another and (I think) generally more useful way as I don't just start a QML program that sort of lives its own life but actually establish a connection between the C++ layer and the QML layer (with the signal/slot connection).
Now to the problem. This runs without errors for the Desktop target. But if I choose the Qt Simulator as target it still runs, but I get this message in the console:
Object::connect: No such signal QDeclarativeRectangle::quit()
When I click the rectangle the app doesn't quit, and the console says:
Signal QDeclarativeEngine::quit() emitted, but no receivers connected to handle it.
Can someone please correct my code?
Bookmarks