2013-07-23 2 views
4

QML 시스템에 C++ 타입을 추가하려고합니다. 나는이 컴파일하려고 해요 때QML 시스템에 C++ 타입을 등록 할 수 없습니다.

#include <QtGui/QGuiApplication> 
#include <QDeclarativeEngine> 
#include <QDeclarativeComponent> 
#include "qtquick2applicationviewer.h" 
#include <QQmlApplicationEngine> 

class FooBar: public QObject { 
    Q_OBJECT 
}; 


int main(int argc, char *argv[]) 
{ 
    QGuiApplication app(argc, argv); 
    QQmlApplicationEngine engine("qml/RBot/main.qml"); 

    qmlRegisterType<FooBar>("io.secorp", 1, 0, "FooBar"); 

    return app.exec(); 
} 

하지만 디버깅에 대한 오류에 geting있어 (내가 .qml 파일이 가져올 수 없습니다, 테스트 전용).

enter image description here

은 어떤 문제가 있습니까?

감사합니다.

+0

을이 질문의 제목은 Qt는 4 읽지 만 문제가 QT4 및 qt5, 그리고 Qt는 창조주의 스크린 샷 모두 태그가 Qt 5.1에 대해 컴파일 중임을 나타냅니다. 내 대답은 Qt 5의 사례를 다룹니다. –

답변

4

지원되지 않는 Qt Quick 1과 2가 혼합되어 있습니다. QDeclarative 헤더는 빠른 1이며 QQml 헤더는 빠른 2.

위한 당신의해야합니다 포함

#include <QtGui/QGuiApplication> 
#include <QQmlApplicationEngine> 
#include <QQmlComponent> 
#include "qtquick2applicationviewer.h" 
#include "foobar.h" 
FOOBAR의 정의는 자신의 헤더에해야하고, QObject를 거기에 포함되어야한다

moc은 마법을 작동합니다.

자세한 내용은 Qt를이 이미보고 된 버그를 참조하십시오

QTBUG-32138 - Hello World for QtQuick2 does not compile with #include when QML debugging is on