Skip to content

Commit

Permalink
Fixes TimerTopTest crash
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Dec 19, 2023
1 parent 0413880 commit ebe8fb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions core/probesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void ProbeSettingsReceiver::run()
m_mutex.lock(); // we only need this for ordering run after waitForSettingsReceived
m_mutex.unlock();

const QString server = QLatin1String("gammaray-") + QString::number(ProbeSettings::launcherIdentifier());
m_socket = new QLocalSocket;
connect(m_socket, &QLocalSocket::disconnected, this, &ProbeSettingsReceiver::settingsReceivedFallback);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -92,12 +93,11 @@ void ProbeSettingsReceiver::run()
this, &ProbeSettingsReceiver::settingsReceivedFallback);
#endif
connect(m_socket, &QIODevice::readyRead, this, &ProbeSettingsReceiver::readyRead);
m_socket->connectToServer(QStringLiteral("gammaray-")
+ QString::number(ProbeSettings::launcherIdentifier()));
m_socket->connectToServer(server);
if (!m_socket->waitForConnected(10000)) {
#ifndef Q_OS_ANDROID
qWarning() << "Failed to connect to launcher, can't receive probe settings!"
<< m_socket->errorString();
<< server << m_socket->errorString();
#endif
settingsReceivedFallback();
}
Expand Down
19 changes: 8 additions & 11 deletions tests/timertoptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Deleter : public QObject
public slots:
void deleteSender()
{
delete sender();
sender()->deleteLater();
}
};

Expand Down Expand Up @@ -150,7 +150,11 @@ private slots:
auto *model = ObjectBroker::model(QStringLiteral("com.kdab.GammaRay.TimerModel"));
QVERIFY(model);

QSharedPointer<QThread> mainThread(new QThread);
QSharedPointer<QThread> mainThread(new QThread, [](QThread *obj) {
obj->quit();
QVERIFY(obj->wait());
obj->deleteLater();
});
mainThread->setObjectName("mainThread");

// main thread free timer operating on "mainThread" object
Expand All @@ -168,7 +172,8 @@ private slots:
threadTimer->setInterval(100);
threadTimer->moveToThread(mainThread.data());

connect(mainThread.data(), &QThread::started, threadTimer.data(), static_cast<void (QTimer::*)()>(&QTimer::start));
connect(mainThread.data(), &QThread::started, threadTimer.data(), QOverload<>::of(&QTimer::start));
connect(mainThread.data(), &QThread::finished, threadTimer.data(), QOverload<>::of(&QTimer::stop));

int timerId = -1;
QTimer::singleShot(500, threadTimer.data(), [&]() {
Expand Down Expand Up @@ -203,14 +208,6 @@ private slots:
QVERIFY(idx.isValid());
}

QTimer::singleShot(0, threadTimer.data(), [&]() {
threadTimer->QObject::killTimer(timerId);
threadTimer->stop();
mainThread->quit();
});

QVERIFY(mainThread->wait());

// remove free timers from model
QMetaObject::invokeMethod(model, "clearHistory");
}
Expand Down

0 comments on commit ebe8fb1

Please sign in to comment.