diff --git a/qt_gui/calculator.cpp b/qt_gui/calculator.cpp index b47851e..ee4e56b 100644 --- a/qt_gui/calculator.cpp +++ b/qt_gui/calculator.cpp @@ -8,13 +8,14 @@ Calculator::Calculator(QObject *parent) : m_lcdText("calculator initial text"), m_timer(this) { - NewKeyEmpty = 1; qDebug() << "Starting calculator thread"; calc_thread.start(); qDebug() << "calculator thread started"; QObject::connect(&m_timer, &QTimer::timeout, this, &Calculator::updateLcd); - m_timer.start(50); + m_timer.start(200); + + updateLcd(); } Calculator::~Calculator(){ @@ -51,16 +52,21 @@ void Calculator::updateLcd() { QString tmp("lcd text:\n"); const char* lcd_buf = get_lcd_buf(); for (int i = 0; i < MAX_ROWS; i++){ + tmp += "|"; for (int j = 0; j < MAX_CHARS_PER_LINE; j++){ tmp += lcd_buf[j + i*MAX_CHARS_PER_LINE]; } - tmp += '\n'; + tmp += "|\n"; } // qDebug() << "update lcd:" << tmp.toStdString().c_str(); setLcdText(tmp); } +void Calculator::setLcdText(const QString &lcdText){ + m_lcdText = lcdText; + emit lcdTextChanged(); +} diff --git a/qt_gui/calculator.h b/qt_gui/calculator.h index 3faec15..3de2395 100644 --- a/qt_gui/calculator.h +++ b/qt_gui/calculator.h @@ -29,7 +29,7 @@ public: ~Calculator(); inline QString lcdText(){return m_lcdText;} - inline void setLcdText(const QString &lcdText){m_lcdText = lcdText;} + void setLcdText(const QString &lcdText); signals: void lcdTextChanged(); diff --git a/qt_gui/main.cpp b/qt_gui/main.cpp index 7b0e294..2ed7d21 100644 --- a/qt_gui/main.cpp +++ b/qt_gui/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include "calculator.h" @@ -8,13 +8,15 @@ int main(int argc, char** argv) { QApplication app(argc, argv); - qmlRegisterType("calculator.lcd", 1, 0, "CLcd"); - QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); Calculator calculator; engine.rootContext()->setContextProperty("_calculator", &calculator); + QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + fixedFont.setStyleHint(QFont::TypeWriter); + engine.rootContext()->setContextProperty("_fixedFont", fixedFont); + return app.exec(); } diff --git a/qt_gui/main.qml b/qt_gui/main.qml index aac8e6e..3eee92a 100644 --- a/qt_gui/main.qml +++ b/qt_gui/main.qml @@ -1,6 +1,5 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 -import calculator.lcd 1.0 ApplicationWindow { @@ -27,11 +26,6 @@ ApplicationWindow anchors.fill: parent } } - - //lcd text from C++ - CLcd { - id: clcd - } //LCD Rectangle { @@ -41,10 +35,9 @@ ApplicationWindow height: 200 Text { objectName: "lcd_text"; - text: clcd.lcdText + text: _calculator.lcdText + font: _fixedFont anchors.centerIn: parent - - onTextChanged: clcd.lcdText = text } }