简体   繁体   中英

Qtest access to ui member

I need to simulate mouse click on UI button using QTest but I can't figure out how to access it.

I've got a MediaPanel class :

class PhMediaPanel : public QWidget
{
    Q_OBJECT

public:
    explicit PhMediaPanel(QWidget *parent = 0);
    //... a lot of functions
private:
    Ui::PhMediaPanel *ui;

};

And a MediaPanelTest :

#include "MediaPanelTest.h"
#include <QObject>

class MediaPanelTest : public QObject
{
    Q_OBJECT
public:
    explicit MediaPanelTest(QObject *parent = 0);

private slots:
    //The tests
};

So how can I simulate button click on Ui::PhMediaPanel *ui member?

Try the following approach:

BUTTONCLASS* button = WIDGET->findChild<BUTTONCLASS*>("name of the button");

As far is i know this should give you the widget without exposing the UI pointer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM