Browse Source

Add wait dialog, fixed ui crash isuue

master
h-4nd-h 4 years ago
parent
commit
115ec041d3
  1. 9
      HarwareTest.pro
  2. 10
      main.cpp
  3. 31
      mainwindow.cpp
  4. 6
      mainwindow.h
  5. 50
      waitdialog.cpp
  6. 30
      waitdialog.h
  7. 37
      waitdialog.ui

9
HarwareTest.pro

@ -18,14 +18,17 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \ SOURCES += \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
/home/hasis/Desktop/pcie/pcie_driver/api/api.cpp /home/hasis/Desktop/pcie/pcie_driver/api/api.cpp \
waitdialog.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
/home/hasis/Desktop/pcie/pcie_driver/api/api.h /home/hasis/Desktop/pcie/pcie_driver/api/api.h \
waitdialog.h
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui \
waitdialog.ui
INCLUDEPATH += /home/hasis/Desktop/pcie/pcie_driver/api/ INCLUDEPATH += /home/hasis/Desktop/pcie/pcie_driver/api/

10
main.cpp

@ -1,11 +1,21 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
#include <QStyle>
#include <QDesktopWidget>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
w.size(),
qApp->desktop()->availableGeometry()
)
);
w.show(); w.show();
return a.exec(); return a.exec();
} }

31
mainwindow.cpp

@ -20,6 +20,9 @@ MainWindow::MainWindow(QWidget *parent)
_usd = new UltraSoundDevice(); _usd = new UltraSoundDevice();
_dial = new WaitDialog();
_dial->setModal(true);
this->setFixedSize(this->width(),this->height()); this->setFixedSize(this->width(),this->height());
ui->prg_binUpload->setVisible(false); ui->prg_binUpload->setVisible(false);
@ -50,6 +53,8 @@ MainWindow::~MainWindow()
delete _settings; delete _settings;
delete _usd; delete _usd;
delete _dial;
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -83,7 +88,12 @@ void MainWindow::on_btn_binUpload_clicked()
auto path = ui->tb_binFile->text(); auto path = ui->tb_binFile->text();
QtConcurrent::run(this, &MainWindow::binaryFileUploader, bar, offset, path); QFutureWatcher<void> watcher;
connect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
auto future = QtConcurrent::run(this, &MainWindow::binaryFileUploader, bar, offset, path);
watcher.setFuture(future);
_dial->exec();
disconnect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -102,7 +112,12 @@ void MainWindow::on_btn_binVerify_clicked()
auto path = ui->tb_binFile->text(); auto path = ui->tb_binFile->text();
QtConcurrent::run(this, &MainWindow::binaryFileVerifier, bar, offset, path); QFutureWatcher<void> watcher;
connect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
auto future = QtConcurrent::run(this, &MainWindow::binaryFileVerifier, bar, offset, path);
watcher.setFuture(future);
_dial->exec();
disconnect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -425,7 +440,12 @@ void MainWindow::on_btn_fpgaProgram_clicked()
auto path = ui->tb_fpgaBit->text(); auto path = ui->tb_fpgaBit->text();
QtConcurrent::run(this, &MainWindow::fpgaProgrammer, bar, offset, path); QFutureWatcher<void> watcher;
connect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
auto future = QtConcurrent::run(this, &MainWindow::fpgaProgrammer, bar, offset, path);
watcher.setFuture(future);
_dial->exec();
disconnect(&watcher, &QFutureWatcher<void>::finished, this, &MainWindow::threadFinished);
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -435,3 +455,8 @@ void MainWindow::newMessage(QString message)
msgBox.setText(message); msgBox.setText(message);
msgBox.exec(); msgBox.exec();
} }
void MainWindow::threadFinished()
{
_dial->close();
}

6
mainwindow.h

@ -4,6 +4,8 @@
#include <QMainWindow> #include <QMainWindow>
#include <QSettings> #include <QSettings>
#include "waitdialog.h"
#include "api.h" #include "api.h"
#define BIN_FILE_PATH "binFilePath" #define BIN_FILE_PATH "binFilePath"
@ -54,10 +56,14 @@ private slots:
void newMessage(QString message); void newMessage(QString message);
void threadFinished();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
WaitDialog* _dial;
QSettings* _settings; QSettings* _settings;
UltraSoundDevice* _usd; UltraSoundDevice* _usd;

50
waitdialog.cpp

@ -0,0 +1,50 @@
#include "waitdialog.h"
#include "ui_waitdialog.h"
#include <QTimer>
#include <QDebug>
WaitDialog::WaitDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::WaitDialog)
{
ui->setupUi(this);
_timer = new QTimer();
connect(_timer, &QTimer::timeout, this, &WaitDialog::timeout);
_timer->start(250);
setText();
}
/*************************************************************************************************/
WaitDialog::~WaitDialog()
{
delete ui;
delete _timer;
}
/*************************************************************************************************/
void WaitDialog::timeout()
{
setText();
}
/*************************************************************************************************/
void WaitDialog::setText()
{
QString str = "Please wait";
for(auto i = 0; i < _state; i++)
str += ".";
_state++;
if(_state > 3)
_state = 0;
ui->l_text->setText(str);
}

30
waitdialog.h

@ -0,0 +1,30 @@
#ifndef WAITDIALOG_H
#define WAITDIALOG_H
#include <QDialog>
namespace Ui {
class WaitDialog;
}
class WaitDialog : public QDialog
{
Q_OBJECT
public:
explicit WaitDialog(QWidget *parent = nullptr);
~WaitDialog();
private slots:
void timeout();
private:
Ui::WaitDialog *ui;
QTimer* _timer;
int _state;
void setText();
};
#endif // WAITDIALOG_H

37
waitdialog.ui

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WaitDialog</class>
<widget class="QDialog" name="WaitDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>219</width>
<height>102</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="l_text">
<property name="geometry">
<rect>
<x>60</x>
<y>40</y>
<width>121</width>
<height>17</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save