이 튜터의 http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-exposecppattributes.html을 기반으로 Qt5에서 C++ 유형의 속성 노출을 QML로 재생 중입니다. 내가 그것을 실행할 때 난 내 문제 오류 창에 오류가 발생했습니다 : 변수 'QQmlComponent 구성 요소를'내가이 오류를 또한 내가 Q_PROPERTY을 사용하여 생성 한 신호가이 오류가 감지되지 않았을뿐만 초기화하지만 불완전한 유형있다오류 : 'QQmlComponent component'변수에 초기화 코드가 있지만 Qt5에 불완전한 형식이 있습니다.
C:\Users\Tekme\Documents\QtStuf\quick\QmlCpp\message.h:15: error: 'authorChanged' was not declared in this scope emit authorChanged(); ^
내 코드
#ifndef MESSAGE_H
#define MESSAGE_H
#include <QObject>
class Message : public QObject
{
Q_OBJECT
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
public:
void setAuthor(const QString &a) {
if (a != m_author) {
m_author = a;
emit authorChanged();
}
}
QString author() const {
return m_author;
}
private:
QString m_author;
};
#endif
이며 내 MAIN.CPP에
#include "message.h"
#include <QApplication>
#include <QQmlEngine>
#include <QQmlContext>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQmlEngine engine;
Message msg;
engine.rootContext()->setContextProperty("msg",&msg);
QQmlComponent component(&engine, QUrl::fromLocalFile("main.qml"));
component.create();
return a.exec();
}
thankssss합니다. 내 모든 오류가 사라집니다. 대단히 감사합니다. qt 문서는 훌륭하지만 나 같은 초보자에게는 약간 어렵습니다. – realtekme
@realtekme 다음 튜토리얼을 수정해야한다고 생각합니다. 이것은 신호 선언이 누락 된 클래스의 예입니다. – thuga
당신이 옳습니다. 특히 혼란 초보자를위한 특히. – realtekme