Expose 'enum QTextToSpeech::State' in QML



  • Hi there
    I am not so much of a QT/C++ buff. Hence, sorry for struggling with the obvious.
    Well, I got stuck trying to react on speech states in QML. Because the emitted enum QTextToSpeech::State is not registered with QML. Please have a look at the snippets below. And most of all, thank you in advance for your hints and helpers!

    in main.cpp I have: 
    
    // load speech module --------------------
    QTextToSpeech* speech = new QTextToSpeech;
    speech->setLocale(QLocale(startLocale));
    
    // load the QML engine --------------------------
    QQmlApplicationEngine engine;
    // making the speech synthesizer class available in QML
    engine.rootContext()->setContextProperty("speech", speech);
    
    then in main.qml
    
    Connections {
                target: speech
                onStateChanged: {
                    console.log("current state: changed!");     // stateChange triggers
                    console.log("the state: "+ speech.state);   // but the state type is not recognised 
                }
            }
    
    
    This produces the following console output: 
    qml: current state: changed!
    QMetaProperty::read: Unable to handle unregistered datatype 'State' for property 'QTextToSpeech::state'
    

    I figured, I must register the QTextToSpeech::state in QML. So I added the following line to main.cpp

    qmlRegisterUncreatableType<QTextToSpeech::State>("QTextToSpeech", 1, 0, "state", "Error: Class uncreatable");
    

    But that gives the following errors, which are too cryptic for me:

    Development/Qt/5.8/clang_64/lib/QtQml.framework/Headers/qqml.h:141: error: no member named 'staticMetaObject' in 'QTextToSpeech::State'
        QML_GETTYPENAMES
        ^~~~~~~~~~~~~~~~
    
    Development/Qt/5.8/clang_64/lib/QtQml.framework/Headers/qqml.h:89: expanded from macro 'QML_GETTYPENAMES'
        const char *className = T::staticMetaObject.className(); \
                                ~~~^
    
    main.cpp:43: in instantiation of function template specialization 'qmlRegisterUncreatableType<QTextToSpeech::State>' requested here
        qmlRegisterUncreatableType<QTextToSpeech::State>("QTextToSpeech", 1, 0, "state", "Error: Class uncreatable");
        ^
    

    And, if there were no errors in C++, I would add an import statement to main.qml

    import QTextToSpeech 1.0
    


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.