Well after trying everything i know and even by adding
QT_MainWindow::QT_MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::QT_MainWindow)
{
ui->setupUi(this);
qRegisterMetaType<QTextCursor>("QTextCursor");
qRegisterMetaType<QTextBlock>("QTextBlock");
}
To my source i still can't modify the text from other Threads in both QTextEdit and QPlainTextEdit also i am using OpenMP with Qt.
can anyone tell me what is the correct way to modify text from other Threads in QTextEdit and QPlainTextEdit because i didn't manage to find anything about that to help me
Here is my source:
void QT_MainWindow::Load()
{
ui->QT_PlainTextEdit->setPlainText("");
std::ifstream file("File.txt");
std::string line;
#pragma omp parallel
{
while ( std::getline(file, line) )
ui->QT_PlainTextEdit->appendPlainText( QString::fromStdString(line));
file.close();
}
}
I managed to get it work only like this
void QT_MainWindow::Load()
{
omp_set_dynamic(0);
omp_set_nested(3);
#pragma omp parallel num_threads(3)
{
ui->QT_PlainTextEdit->setPlainText("");
}
}
But if i try to set text
void QT_MainWindow::Load()
{
omp_set_dynamic(0);
omp_set_nested(3);
#pragma omp parallel num_threads(3)
{
ui->QT_PlainTextEdit->setPlainText("TEST");
}
}
I get this error
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTextDocument(0x3bbc758), parent's thread is QThread(0x3bd140), current thread is QThread(0x3bbcb68)
The program has unexpectedly finished.
also
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTextDocument(0x465bfc0), parent's thread is QThread(0x3f3ad60), current thread is QThread(0x466d450)QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTextDocument(0x465bfc0), parent's thread is QThread(0x3f3ad60), current thread is QThread(0x46eebe0)HEAP[app.exe]:
Invalid address specified to RtlFreeHeap( 00000000023F0000, 0000000003F3DC40 )