Reputation: 13
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?
Upvotes: 1
Views: 1260
Reputation: 24416
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.
Upvotes: 1