View Full Version : Connecting SIGNAL to functions
vyalmicro
5th November 2014, 16:40
Is there any way to connect SIGNAL to a function which have global scope? Like when button is clicked a function display_error() is evoked? Is it possible or I would need to make a custom class for the widget inheriting from QPushButton adding display_error function in it?
I want to ignore the Object Oriented design as I am more of a C guy.
wysota
5th November 2014, 17:26
It is possible in Qt5. In Qt4 you'd have to create a wrapper class to make the call to the function.
vyalmicro
5th November 2014, 17:36
A custom class inheriting from QObject who have display_error() function as SLOT would work? like this example:
#include <QObject>
class Counter : public QObject
{
Q_OBJECT
public:
Counter() { m_value = 0; }
int value() const { return m_value; }
public slots:
void setValue(int value);
void display_error();
signals:
void valueChanged(int newValue);
private:
int m_value;
};
wysota
5th November 2014, 19:41
Yes, but I rather meant that the class accepts a function pointer as its constructor's argument and executes the function when it receives a signal. Then you can attach any global function to it.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.