I'm not sure why you are making things so complex, try this:
class LogEvent
: public QEvent {public:
const QString &string
() const { return m_str;
} private:
};
public:
Log(){}
void run(){ exec(); }
protected:
if(e
->type
()==QEvent::MaxUser-1){ logData(static_cast<LogEvent*>(e)->string());
}
}
};
class LogEvent : public QEvent {
public:
LogEvent(const QString &str) : QEvent(QEvent::MaxUser-1), m_str(str){}
const QString &string() const { return m_str; }
private:
QString m_str;
};
class Log : public QThread {
public:
Log(){}
void run(){ exec(); }
static void log(const QString &str){ QCoreApplication::postEvent(new LogEvent(str)); }
protected:
void customEvent(QEvent *e){
if(e->type()==QEvent::MaxUser-1){
logData(static_cast<LogEvent*>(e)->string());
}
}
};
To copy to clipboard, switch view to plain text mode
No need for any mutexes or artificial event queues.
Bookmarks