0
QML에서 C++로 목록을 보내려고합니다. 나는 문자열과 성공의 정수로 시도했다하지만 난 QVariant으로하려고하면 오류 얻을 :QML에서 C++로 QVariant 전달
QObject::connect: No such slot MyClass::cppSlot(QVariant) in ../test_2206/main.cpp:31
내 main.qml을
import QtQuick 2.4
import QtQuick.Layouts 1.1
import Material.ListItems 0.1 as ListItem
import Material.Extras 0.1
import QtQuick.Controls 1.3 as QuickControls
import QtQuick.Controls 1.4
import Material 0.2
Window {
visible: true
property var listCloud: ["nuage1", "nuage2", "nuage3", "nuage4"]
id: item
width: 100; height: 100
signal qmlSignal(variant msg)
/* MouseArea {
anchors.fill: parent
onClicked: item.qmlSignal("Hello from QML")
}*/
Rectangle{
id:sousRect
color:"red"
width:100; height:100
Button{
id:buttonTest
onClicked: {
item.qmlSignal(listCloud)
}
}
}
}
내 MAIN.CPP
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlProperty>
#include <QQmlComponent>
#include <QDebug>
#include "myclass.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
QObject *object = component.create();
MyClass myClass;
QObject::connect(object, SIGNAL(qmlSignal(QVariant)),
&myClass, SLOT(cppSlot(QVariant)));
return app.exec();
}
내에서 MyClass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QDebug>
#include <QString>
#include <QList>
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *parent = 0);
signals:
public slots:
void cppSlot(QVariant &msg);
};
#endif // MYCLASS_H
내 myclass.cpp
#include "myclass.h"
MyClass::MyClass(QObject *parent):
QObject(parent)
{
}
void MyClass::cppSlot(QVariant &msg){
qDebug() << "c++: bien reçu chef " << msg;
}
이 신호에 QVariant 매개 변수를 넣을 수없는 이유를 알지 못합니다. 도움이됩니다.
을 사용하십시오. var 대신 변형을 사용하여 보았습니까? 변형 유형은 일반 속성 유형입니다. 이는 구식이며 기존 응용 프로그램을 지원하기 위해서만 존재합니다. 새 응용 프로그램은 var 유형 속성을 사용해야합니다. – RvdK
또한 variant를 명시 적으로 사용 하시겠습니까? listCloud는 문자열이있는 목록이므로 QStringList도 마찬가지입니다. – RvdK
문자열 목록뿐만 아니라 객체 목록을 전달해야하므로 variant를 사용하고 싶습니다. 당신은'property vairant listCloud' 대신'property var listCloud'를 써야한다고 생각하니? – Cam