Commit f5e3b084 authored by Aaron J. Seigo's avatar Aaron J. Seigo
Browse files

libqalculate uses a global (!) object for the calculator; refcount our use of it

still not entirely safe -> if ANYTHING else uses the CALCULATOR object, iow
uses libqalculate, problems will ensue.

libqalculate really ought to be improved in this regard.
parent 5aeefe18
......@@ -37,10 +37,13 @@
#include <KIO/Job>
#include <KIO/NetAccess>
QAtomicInt QalculateEngine::s_counter;
QalculateEngine::QalculateEngine(QObject* parent):
QObject(parent)
{
m_lastResult = "";
s_counter.ref();
if (!CALCULATOR) {
new Calculator();
CALCULATOR->terminateThreads();
......@@ -53,7 +56,10 @@ QalculateEngine::QalculateEngine(QObject* parent):
QalculateEngine::~QalculateEngine()
{
delete CALCULATOR;
if (s_counter.deref()) {
delete CALCULATOR;
CALCULATOR = NULL;
}
}
void QalculateEngine::updateExchangeRates()
......
......@@ -20,6 +20,7 @@
#ifndef QALCULATEENGINE_H
#define QALCULATEENGINE_H
#include <QAtomicInt>
#include <QObject>
class KJob;
......@@ -48,6 +49,7 @@ signals:
private:
QString m_lastResult;
static QAtomicInt s_counter;
};
#endif // QALCULATEENGINE_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment