
Originally Posted by
wysota
That won't work. Mutex or no mutex... You can't update the list from within external threads. Instead emit a signal from other threads that will be connected to a custom slot in the view that will add the items. You won't need any special treatment then.
Hi wysota, thanks for the reply. Your suggestion seems straight forward enough but I can't get it to work.
I've defined the following in MainWindow.h in class MainWindow
void logMessage(const std::string& sMessage) {
boost::mutex::scoped_lock scoped_lock(m_oMessageListMutex);
emit logMessageSignal
(QString(sMessage.
c_str()));
}
signals:
void logMessageSignal(QString& sMessage);
public slots:
void messageReceived(QString& sMessage) {
}
void logMessage(const std::string& sMessage) {
boost::mutex::scoped_lock scoped_lock(m_oMessageListMutex);
emit logMessageSignal(QString(sMessage.c_str()));
}
signals:
void logMessageSignal(QString& sMessage);
public slots:
void messageReceived(QString& sMessage) {
QListWidgetItem *item = new QListWidgetItem(sMessage, messagesListWidget);
}
To copy to clipboard, switch view to plain text mode
logMessage() is called from the worker threads.
In MainWindow.cpp I have connected as follows (called from the main thread):
connect(this, SIGNAL(logMessageSignal(QString& sMessage)), this, SLOT(messageReceived(QString& sMessage)));
connect(this, SIGNAL(logMessageSignal(QString& sMessage)), this, SLOT(messageReceived(QString& sMessage)));
To copy to clipboard, switch view to plain text mode
I get a runtime error:
Object::connect: No such signal MainWindow::logMessageSignal(QString&sMessage)
Object::connect: (sender name: 'MainWindow')
Object::connect: (receiver name: 'MainWindow')
cheers
Dave
Bookmarks