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);
fooObject.moveToThread(&thread);
QObject::connect(&thread,
SIGNAL(started
()),
&fooObject,
SLOT(start_slot
()));
thread.start();
return a.exec();
}
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();
}
To copy to clipboard, switch view to plain text mode
In Foo header file:
QProcess* testProcess;
To copy to clipboard, switch view to plain text mode
Slot, invoked after thread started:
void Foo::start_slot()
{
connect(testProcess, SIGNAL(finished(int)), this, SLOT(finish_slot()));
testProcess->start("uname -a"); //just for example
}
void Foo::start_slot()
{
testProcess = new QProcess;
connect(testProcess, SIGNAL(finished(int)), this, SLOT(finish_slot()));
testProcess->start("uname -a"); //just for example
}
To copy to clipboard, switch view to plain text mode
After completion this slot SIGSEGV occurs:
void Foo::finish_slot()
{
delete (testProcess);
QObject* moduleObject
= engineObject
->rootObjects
().
first()->findChild<QObject
*>
("testModule");
}
void Foo::finish_slot()
{
delete (testProcess);
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
}
To copy to clipboard, switch view to plain text mode
But this works fine...
void Foo::finish_slot()
{
QObject* moduleObject
= engineObject
->rootObjects
().
first()->findChild<QObject
*>
("testModule");
delete (testProcess);
}
void Foo::finish_slot()
{
QObject* moduleObject = engineObject->rootObjects().first()->findChild<QObject*>("testModule");
QMetaObject::invokeMethod(moduleObject, "test");
delete (testProcess);
}
To copy to clipboard, switch view to plain text mode
Is it bug or my mistake? Thanks!
Bookmarks