Engine
Engine

Reputation: 5432

how to interact with QPushButton in a static Method

I have Popup window with 2 button and I want to use the SIGNAL and SLOT of those buttons in a static Methode when I use

connect(allbox->getAcceptButton(),SIGNAL(clicked()),this,SLOT(dosmt());

the program crashs any Idea how I can solve this. thanks for your help

Upvotes: 0

Views: 213

Answers (3)

Hennaldo
Hennaldo

Reputation: 155

 class Test: public QObject
 {
     Q_OBJECT
 ...
 public:
     static void testMethod();
 public slots:
     void testSlot();

 };

Test::Test()
{
    QObject::connect(button, SIGNAL(clicked(), this, SLOT(testSlot()));
}

Test::testSlot()
{
    Test::testMethod();
}

just a short example, you have to connect a SIGNAL with a SLOT as it is documented by Qt http://doc.qt.digia.com/qt/signalsandslots.html

Upvotes: 0

Hennaldo
Hennaldo

Reputation: 155

You have to write a slot which calls the static method

Upvotes: 1

cmannett85
cmannett85

Reputation: 22366

You have already asked a similar question, and the answer is the same: You cannot use this in a static method, so you will have to pass an object that has a dosmt() slot to it as well.

Upvotes: 0

Related Questions