MatrixSan
10th December 2016, 12:49
Hello! I'm trying to write GUI for some console applications and I'm stuck on strange problem...
In main function:
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QQmlApplicationEngine engine(QUrl::fromLocalFile("test.qml"));
Foo fooObject(&engine);
QThread thread;
fooObject.moveToThread(&thread);
QObject::connect(&thread, SIGNAL(started()), &fooObject, SLOT(start_slot()));
thread.start();
return a.exec();
}
In Foo header file:
QProcess* testProcess;
Slot, invoked after thread started:
void Foo::start_slot()
{
testProcess = new QProcess;
connect(testProcess, SIGNAL(finished(int)), this, SLOT(finish_slot()));
testProcess->start("uname -a"); //just for example
}
After completion this slot SIGSEGV occurs:
void Foo::finish_slot()
{
delete (testProcess);
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
}
But this works fine...
void Foo::finish_slot()
{
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
delete (testProcess);
}
Is it bug or my mistake? Thanks!
In main function:
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QQmlApplicationEngine engine(QUrl::fromLocalFile("test.qml"));
Foo fooObject(&engine);
QThread thread;
fooObject.moveToThread(&thread);
QObject::connect(&thread, SIGNAL(started()), &fooObject, SLOT(start_slot()));
thread.start();
return a.exec();
}
In Foo header file:
QProcess* testProcess;
Slot, invoked after thread started:
void Foo::start_slot()
{
testProcess = new QProcess;
connect(testProcess, SIGNAL(finished(int)), this, SLOT(finish_slot()));
testProcess->start("uname -a"); //just for example
}
After completion this slot SIGSEGV occurs:
void Foo::finish_slot()
{
delete (testProcess);
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
}
But this works fine...
void Foo::finish_slot()
{
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
delete (testProcess);
}
Is it bug or my mistake? Thanks!