jeudi 28 décembre 2017

Calling a C++ function from Qml asynchronously or in a new thread

I completed my entire project on building an application that basically fetches sql query result based on some user input combination in the GUI and I believe that there is some performance issue when calling a Q_INVOKABLE function in C++ code which performs some computation to produce the query and also run the query and return the result, so I wanted to know if there is a way to run that function in a separate thread from qml. The skeleton is somewhat like this:

Result.h

class Result{
public:
   Q_INVOKABLE void on_submit_button_clicked(); 
}

Result.cpp

Result::on_submit_button_clicked()
{
        /*Code that prepare the query*/

        /*Code that runs the query using a Qthread*/
}

main.qml

ApplicationWindow
{
    id:appwindow


    /*Other parts of the GUI*/
    Button{
        id:submitButton
        onClicked:{
              result_object.on_submit_button_clicked() //how to run this function in a new thread ? 
              /*code to load my table view columns*/
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire