创建 QTextEdit 时出现分段错误

问题描述 投票:0回答:0

我写了一个最小的例子,其中我的应用程序崩溃了。我不明白出了什么问题。我希望有人能思考一下这个段错误的原因。

如果你增加QTimer超时,例如,甚至到10毫秒,也不会下降。还。这很奇怪,如果你删除 a.setStyleSheet(result),一切都会好起来的。


#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;
};
c++ qt qthread qtextedit qtimer
© www.soinside.com 2019 - 2024. All rights reserved.