1

我对qt有点陌生,有点卡住了。我想知道是否可以使用 qt 快速控件 2 从 c++ 模拟按钮单击 qml 中的按钮,这将如何完成?

我知道它可以将信号从 qml 发送到 c++,但是有可能以其他方式进行吗?

4

1 回答 1

1

我看到你从 C++ 说的。在这种情况下,有Qt Test。以文档中的示例为例:

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

您可以使用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()

您将使用该mouseClick()函数来模拟单击按钮。

还有qmlbench,这是最近在博客上写的。

于 2017-05-13T16:43:12.327 回答