Cannot connect MyClass::data(QVariant) to (null)::updateData(QVariant)
-
i am running Qt on Ubuntu not windows
-
It's Window not Windows. Window here refers to the root element which you have used in the QML file.
I think you must start with the basics of QML first. -
Thanks, QMetaObject::InvokeMethod works better than signals/slot for C++ invoking QML. From same document, QML invoking C++, i could not compile, below is my code. Can help?
@
-----------------header file myclass----------------
#include <QDebug>class MyClass: public QObject
{
Q_OBJECT
public slots:
void cppSlot(const QString &msg){
qDebug()<<"Called the c++ slot with message"<<msg;
}
};-----------------cpp file----------------
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
#include <QDebug>
#include "myclass.h"int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);QQuickView view("qrc:///main.qml"); QObject *item= view.rootObject(); MyClass myClass; QObject::connect(item,SIGNAL(qmlSignal(QString)),&myClass,SLOT(cppSlot(QString))); return app.exec();
}
-----------------qml file----------------
import QtQuick 2.2
import QtQuick.Controls 1.1ApplicationWindow {
id: item
visible: true
width: 640
height: 480
title: qsTr("Hello World")signal qmlSignal(string msg)
MouseArea{
anchors.fill:parent
onClicked: item.qmlSignal("Hello from QML")
}
}
@ -
What error do you get during compiling?
-
To use ApplicationWindow/Window you will need to use QQmlApplicationEngine and not QQuickView. The error should be at runtime not compiletime.
-
error at QQuickView and QObject statement.
@
no matching function for call to 'QQuickView::QQuickView(const char[16])'
cannot convert 'QQuickItem' to 'QObject *' in initialization.
@ -
Use QQmlApplicationEngine for loading ApplicationWindow/Window.
@
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
QObject *rootObject= engine.rootObjects().first();
QObject::connect(rootObject,SIGNAL(qmlSignal(QString)),
&myClass,SLOT(cppSlot(QString)));
@Above should work.
-
insert statement 'MyClass myclass;' before QObject::connect.
2 error encounter:
undefined reference to 'vtable for MyClass'
ld returned 1 exit status -
Run qmake and then Rebuild.
-
I created a new header file for class 'MyClass'
Now my error is
QQmlApplicationEngine failed to load component
Assert:"!isEmpty()" in file /include/QtCore/qlist.h
The program has unexpectedly finished. -
I don't know. You must have misplaced something somewhere. Better would be to create a new project with that class and qml file. Use the code that i posted above to launch the qml file. It is not a very complicated code.
-
Thanks very much.