Search code examples
c++qtgui-testingqtestlib

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?


Solution

  • 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.