2012-07-18 1 views
4

Q_INVOKABLE 함수를 호출하여 QML에 문제가 있습니다. 내가 Q_INVOKABLE 등의 기능을 표시하지만 내가지고있어 오류 QML - Q_INVOKABLE 함수

TypeError: Result of expression 'azdownloader.setData' is not a function 
TypeError: Result of expression 'azdownloader.perform' is not a function 

나는이 수업이 있습니다

typedef QString lyricsDownloaderString; 

class lyricsDownloader : public QObject 
{ 
public: 
    Q_INVOKABLE virtual short perform() = 0; 
    Q_INVOKABLE inline void setData(const string & a, const string & t); // set artist and track 
// some other data 

protected: 
    lyricsDownloader(const string & a, const string & t) : artist(a), track(t) {} 
    /*other data*/ 
}; 

class AZLyricsDownloader : public lyricsDownloader 
{ 
public: 
    AZLyricsDownloader() : lyricsDownloader("", "") {} 
    AZLyricsDownloader(const string & a, const string & t) : lyricsDownloader(a, t) {} 
    Q_INVOKABLE short perform(); 
    Q_INVOKABLE inline void setData(const string & a, const string & t);// set artist and track 
/*other data*/ 

MAIN.CPP main.qml에서

Q_DECL_EXPORT int main(int argc, char *argv[]) 
{ 
     QApplication app(argc, argv); 

     mainWindow viewer; 

     qmlRegisterUncreatableType<lyricsDownloader>("MaeLyrica", 1, 0, "lyricsDownloader", ""); 
     qmlRegisterType<AZLyricsDownloader>("MaeLyrica", 1, 0, "AZLyricsDownloader"); 
     viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); 
     viewer.setMainQmlFile(QLatin1String("qml/maelyrica/main.qml")); 
     viewer.showFullScreen(); 

     return app.exec(); 
} 

에서를

import QtQuick 1.1 
import com.nokia.meego 1.0 
import com.nokia.extras 1.0 
import MaeLyrica 1.0 

//property color fontcolor: "white" 

PageStackWindow 
{ 
    id: pagestackwindow 
    visible: true 
    MainPage 
    { 
     id: mainview 
    } 
    initialPage: mainview 
    AZLyricsDownloader 
    { 
     id: azdownloader 
    } 
} 

페이지의

import QtQuick 1.1 
import com.nokia.meego 1.0 

Page 
{ 
/*some gui elements*/ 

     Button 
     { 
      id: go 
      text: "Go!" 
      width: parent.width 
      onClicked: 
      { 
       goLoader.source = "ShowLyricsPage.qml" 
       pageStack.push(goLoader.item) 
       azdownloader.perform() 
       showLyricsPage.busyind.visible = false 
      } 
     } 
    } 
/*dialogs and toolbar definitions*/ 
} 

다른 하나

import QtQuick 1.1 
import com.nokia.meego 1.0 

Sheet { 
    id: sheet 

    acceptButtonText: "Save" 
    rejectButtonText: "Cancel" 
    onAccepted: 
    { 
     if (artistfield.text == "" || trackfield.text == "") // check whether empty 
     { 
      emptyfieldsdialog.open() 
     } 
     else 
     { 
      selecttrack.text = artistfield.text + " - " + trackfield.text 
      azdownloader.setData(artistfield.text, trackfield.text) 
     } 
    } 

    content: Rectangle { /*some content here*/ } 

    /*dialog definition*/ 

내가 뭐하는 거지 무슨 잘못?

답변

16

당신이 여기에 붙여 넣을 것으로 판단, 피상적 인 검사는 수행하여 우리 모두가 밖으로 시작 일을 관리했습니다 나타냅니다

당신은 당신의 QObject를 기반으로 클래스에서 Q_OBJECT 매크로를 잊어 버렸습니다.

클래스가 없으면 신호, 슬롯 및 기타 유사한 기능 (예 : Q_INVOKABLE)이 예상대로 작동하지 않습니다. 희망이 도움이 :)

+0

을 지금은 moc_lyricsDownloader.cpp 받고 있어요 : 76 : 오류 : lyricsDownloader :: 사항 setData'로 정의되지 않은 참조 (표준 : : basic_string <문자, 표준 : : char_traits , 표준 : : 할당 > const를 & , std :: basic_string , std :: allocator > const &) ' – marmistrz

+0

EDIT : 클래스 정의에 함수 본문을 추가 한 후 모두 괜찮습니다. – marmistrz

+0

나는 똑같은 문제가 있었고 이것으로 인해 해결되었다 :-) 고마워! –