Newbie in need to quick ramp up on how to use QML and C++ to do some basic processing



  • Need some example to help me in understanding how C++ and QML really hooks up.

    a) I have a form component in QML

    @import QtQuick 1.0

    Item
    {
    id:complaintpage
    Rectangle {

    property string fontfamily:"Helvetica"
    
    id: reccomplaint
    width: 400
    height: 400
    border.color: "white"
    anchors.fill: parent
    
    Column
    {
        id:labelarea
         width: parent.width/2
        height: parent.width/2
        spacing: 4
    
        Text {
            id:lblname
            text: qsTr("Name")
            width: 100
            height: 21
            font.family: reccomplaint.fontfamily
        }
    
    
        Text {
            id:lblemail
            text: qsTr("Email")
            width: lblname.width
            font.family: reccomplaint.fontfamily
        }
    
        Text {
            id:lblcomplaint
            text: qsTr("Complaint/Comment")
            width: lblname.width
            height: 12
            font.family: reccomplaint.fontfamily
        }
    }
    
    Column
    {
        id:textarea
        width: parent.width/2
       height: parent.width/2
        TextInput
        {
            id: txtname
            width: parent.width - (2 * font.pointSize)
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            font.pointSize: 17
            color: "black"
            echoMode: textField.echoMode
            onTextChanged: textField.textChanged(text)
            onFocusChanged: {
                if(focus){
                    textField.border.color = "#569ffd"
                }else{
                    textField.border.color = "lightgray"
                }
            }
        }
        TextInput
        {
            id: txtemail
            font.pointSize: 17
            color: "black"
            onTextChanged: textField.textChanged(text)
            onFocusChanged: {
                if(focus){
                    textField.border.color = "#569ffd"
                }else{
                    textField.border.color = "lightgray"
                }
            }
        }
    
        TextInput
        {
            id: txtcomplaint
            font.pointSize: 17
            color: "black"
            onTextChanged: textField.textChanged(text)
            onFocusChanged: {
                if(focus){
                    textField.border.color = "#569ffd"
                }else{
                    textField.border.color = "lightgray"
                }
            }
        }
    }
    
    Row {
        Button{
            id: submitButton
            ///buttonColor: "lightgrey"
            text: "Submit"
        }
    
        Button{
            id: cancelButton
            ///buttonColor: "lightgrey"
            text: "Cancel"
        }
    }
    

    }

    }
    @

    b) And I have a function in C++ to handle the submission of the contents of this form when the submit button is clicked.

    @class ProcessRequests : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString username READ setusername WRITE username)
    Q_PROPERTY(QString useremail READ setuseremail WRITE useremail)
    Q_PROPERTY(QString usercomplaint READ setusercomplaint WRITE usercomplaint)

    private:
    QString _userid;
    QString _useremail;
    QString _usercomplaint;

    public:
    
    void setusername(){}
    void setuseremail(){}
    void setusercomplaint(){}
    
    QString username(){ return _userid;}
    

    QString useremail(){ return _useremail;}
    QString userncomplaint(){ return _usercomplaint;}

    ProcessRequests()
    {}
    ~ProcessRequests(){}
    
    void SubmitComplaint(){
    
    }
    

    };

    c) In my main.cpp file, I have the following to make connections to the QML viewer

    #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"
    #include <QDeclarativeContext>

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile&#40;QLatin1String("qml/QMLUIProject_One/main.qml"&#41;);
    viewer->showExpanded();
    //Product.cpp
    QDeclarativeEngine *engine = viewer->engine();
     QDeclarativeContext *context = new QDeclarativeContext(engine);
    context->setProperty("ProcessRequests", ""); 
    //Your QML File
    //Product.YourFunction(args);
    
    return app->exec&#40;&#41;;
    

    }@

    d) But I am not certain what comes next and would appreciate any help in completing this and learning a bit more about QML and QT in the process


Log in to reply
 

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