I have a class called Global and it does a repetitive task once in a while via a static function... This function is called through many different classes so it is important to be static so as not to create objects all the time.
glob.h:
{
Q_OBJECT
public:
static void send_name
(QString color_name
);
...
Q_SIGNALS:
};
class Global: public QObject
{
Q_OBJECT
public:
static void send_name(QString color_name);
...
Q_SIGNALS:
send_color(QString color_name);
};
To copy to clipboard, switch view to plain text mode
glob.cpp:
void Global
::send_name(QString color_name
){ if(_window_loaded_){
/*SEND MESSAGE WITH COLOR_NAME*/
Q_EMIT send_color(color_name);
}
}
void Global::send_name(QString color_name){
if(_window_loaded_){
/*SEND MESSAGE WITH COLOR_NAME*/
Q_EMIT send_color(color_name);
}
}
To copy to clipboard, switch view to plain text mode
Inside my MainWindow class I have to connect the send_color message sent by my static function to a local function so as to update some gui content.
I know that there are many many threads about this but, believe me, I've searched all of them and nothing worked for me. I searched in depth the mailing lists and still nothing. I even tried to use QCustomEvent with qApplication->postEvent() but it is deprecated and it is suggested to use QEvent , which doesn't have setdata() function though, so it is no usable for this case (?)
I've spent my morning searching about this, so all suggestions are appreciated!
Bookmarks