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

13th March 2011, 19:20

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;

// 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() ) );


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:


import QtQuick 1.0

width: 360
height: 360

text: "Hello World"
anchors.centerIn: parent

anchors.fill: parent

14th March 2011, 11:21
You're missing:

#include <QDeclarativeEngine>