1
votes

I'am kinda new to qt and got a little bit stuck. Im wondering if it is possible to simulate a button click from c++ for a button in qml with qt quick controls 2 and how would this be done?

I know its possible to send signals from qml to c++ but is it possible doing it the other way somehow?

1
What is it, you try to achive by that?derM
Well im trying to get the real time it takes for ui objects to react. Like start a counter > simulate a click > do some other things with ui objects > stop counter. Im doing a comparison of Qt and native android/ios dev.Dragan

1 Answers

1
votes

I see that you said from C++. In that case, there's Qt Test. Taking the example from the docs:

class MyFirstBenchmark: public QObject
{
    Q_OBJECT
private slots:
    void myFirstBenchmark()
    {
        QString string1;
        QString string2;
        QBENCHMARK {
            string1.localeAwareCompare(string2);
        }
    }
};

You can do this with TestCase.

TestCase {
    id: top
    name: "CreateBenchmark"

    Button {
        id: button
        onClicked: doSomeStuff()
    }

    function benchmark_create_component() {
        mouseClick(button);
    }
}

RESULT : CreateBenchmark::benchmark_create_component:
     0.23 msecs per iteration (total: 60, iterations: 256)
PASS   : CreateBenchmark::benchmark_create_component()

You would use the mouseClick() function to simulate a click on a button.

There's also qmlbench, which was blogged about recently.