From 094d7a04b362d76186892f044d0eb22d6a341a9f Mon Sep 17 00:00:00 2001 From: NeoTheFox Date: Sat, 16 Apr 2016 12:41:14 +0300 Subject: [PATCH] Updated printMsg to prevent possible bugs --- mainwindow.cpp | 11 ++++++----- mainwindow.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7aaf194..5e94410 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -40,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : recentMenu->setTitle("Recent files"); ui->menuFile->insertMenu(ui->actionSettings, recentMenu); ui->menuFile->insertSeparator(ui->actionSettings); + terminalCursor = ui->terminal->textCursor(); //Init baudrate combobox ui->baudbox->addItem(QString::number(4800)); @@ -631,14 +632,14 @@ void MainWindow::printMsg(QString text) { if(supressWait && text.startsWith("wait")) return; //Get the cursor and set it to the end - QTextCursor cursor = ui->terminal->textCursor(); - cursor.movePosition(QTextCursor::End); + terminalCursor.movePosition(QTextCursor::End); //Paste the text - cursor.insertText(text); + terminalCursor.insertText(text); - //Apply - ui->terminal->setTextCursor(cursor); + //Scroll to the bottom + ui->terminal->verticalScrollBar()->setValue( + ui->terminal->verticalScrollBar()->maximum()); } void MainWindow::checkStatus() diff --git a/mainwindow.h b/mainwindow.h index 52f6e76..ae95043 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -59,6 +59,7 @@ protected: QStringList EEPROMSettings; QStringList userHistory; QSerialPortInfo printerinfo; + QTextCursor terminalCursor; void closeEvent(QCloseEvent *event); bool eventFilter(QObject *target, QEvent *event);