PDA

View Full Version : Need some help with connecting to a signal from coming from QML in c++.



najamelan
13th March 2011, 18:20
Hi,

to learn qt quick and understand better the basics, I made a hello world project in Qt Creator. Now I have thrown out the qmlapplicationviewer class in order to see the most simple functioning qml app and make sure I understand it. Now I get stuck here:



// main.cpp

#include <QtGui/QApplication>
#include <QDeclarativeView>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);


QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("qml/untitled/main.qml"));

// QObject::connect( ( QObject* ) view.engine(), SIGNAL( quit() ),( QObject* ) &app, SLOT( quit() ) );

// ^--works | doesn't work --v

QObject::connect( view.engine(), SIGNAL( quit() ), &app, SLOT( quit() ) );

view.show();

return app.exec();
}


When i try to build this I get the following error:

\main.cpp:13: error: no matching function for call to 'QObject::connect(QDeclarativeEngine*, const char*, QApplication*, const char*)'

qobject.h:198: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

qobject.h:313: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const

Note that the commented out line works as expected... I would think the upcasting should be implicit... In no sample code in the documetation do I see the need for casts...
Can anyone explain to me what is going on?

The qml file is unchanged from how the wizard generated it:


//main.qml

import QtQuick 1.0

Rectangle
{
width: 360
height: 360

Text
{
text: "Hello World"
anchors.centerIn: parent
}

MouseArea
{
anchors.fill: parent
onClicked:
{
Qt.quit();
}
}
}

wysota
14th March 2011, 10:21
You're missing:

#include <QDeclarativeEngine>