samedi 21 février 2015

C++11 thread in qt 5


//MainWindow.cpp
void MainWindow::threadedFunction()
{
myDialog = new MyDialogs(list,processList,this);
myDialog->show();
}

void MainWindow::createNewDialog()
{
getProcesses();
//threadedFunction(); //This works fine.
std::thread tx = std::thread(&MainWindow::threadedFunction,this);
tx.join();
}

//MyDialog.cpp

MyDialogs::MyDialogs(QList<int> lists,QStringList list,QObject *parent):QDialog(0)
{

QVBoxLayout *toplay = new QVBoxLayout(this);
listWidget = new QListWidget(this);

x<<list;
l<<lists;
listWidget->addItems(x);
toplay->addWidget(listWidget);


connect(listWidget,SIGNAL(doubleClicked(QModelIndex)),
this,SLOT(getProcessString(QModelIndex)));
}

void MyDialogs::getProcessString(QModelIndex index)
{
selectedProcessString = index.data().toString();
rowIndex = index.row();
}


Already set in pro file.



CONFIG += c++11


when I call threadedFunction directly the code works fine. But the above mentioned code gives me runtime error. If I use only qDebug statements in threadedFunction and remove myDialog code, the code runs fine even with the threads. What is the problem?


Aucun commentaire:

Enregistrer un commentaire