I wrote a minimal example in which my application crashes. I can't figure out what's wrong. I hope someone has thoughts about the reason for this segfault.
if you increase the QTimer timeout, for example, even to 10 milliseconds, there will be no falling. Also. which is strange, if you remove a.setStyleSheet(result), everything will be fine too.
#include "mainwindow.h"
#include "test.h"
#include <QApplication>
#include <QThread>
#include <memory>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString result;
QFile textFile("/home/narina/workspace/CubSatPanel/ulib/src/styles/Gravira.qss");
if (textFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
result = textFile.readAll();
textFile.close();
}
a.setStyleSheet(result);
std::unique_ptr<Test> communicator = std::make_unique<Test>();
QThread communicatorThread;
communicator.get()->moveToThread(&communicatorThread);
QObject::connect(&communicatorThread, SIGNAL(started()),communicator.get(), SLOT(run()));
MainWindow w;
communicatorThread.start();
w.show();
int ret = a.exec();
communicatorThread.exit();
communicatorThread.wait();
return ret;
}
#include <QObject>
#include <QTimer>
#include <QTextBrowser>
class Test : public QObject
{
Q_OBJECT
public:
Test() = default;
public slots:
void tester()
{
QTextEdit logTextBrowser;
}
void run()
{
m_timer = new QTimer(this);
m_timer->setInterval(1);
m_timer->setSingleShot(false);
connect(m_timer, SIGNAL(timeout()), this, SLOT(tester()));
m_timer->start();
}
private:
QTimer* m_timer;
};