#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setGeometry(0,0,480,272); ui->teMain->setFocus(); tbShowState = 0; ui->cbPort->setCurrentIndex(1); //ui->toolBox->setVisible(false); threadM = new MyThread(this); //Attention "this"!!!! connect(this, SIGNAL(openPortMain(int)), threadM, SLOT(openPortThread(int))); connect(threadM, SIGNAL(sendStr(QString)), this, SLOT(getStr(QString))); } MainWindow::~MainWindow() { threadM->quitSignal = 1; delete ui; } void MainWindow::on_butCD_clicked() { int portIndex; portIndex = ui->cbPort->currentIndex(); emit openPortMain(portIndex); } void MainWindow::getStr(QString str) { ui->teMain->append(str); if(str.contains("Open")) { on_cbBaud_currentIndexChanged(); threadM->start(); ui->cbPort->setEnabled(false); ui->cbPort->setStyleSheet("color: rgba(0,0,0,0);"); ui->butKeyboard->setEnabled(false); ui->butKeyboard->setStyleSheet("color: rgba(0,0,0,0);"); } else if(str.contains("Close")) { threadM->quitSignal = 1; ui->cbPort->setEnabled(true); ui->cbPort->setStyleSheet("border: 1px groove white; color: rgba(255,255,255,255);"); ui->butKeyboard->setEnabled(true); ui->butKeyboard->setStyleSheet("border: 1px groove white; color: rgba(255,255,255,255);"); if(!threadM->isRunning()) { qDebug() << "MyThread qiut!"; ui->teMain->append("MyThread qiut!"); } ui->teMain->setFocus(); } } void MainWindow::on_butShowTb_clicked() { if(tbShowState) { tbShowState = 0; ui->toolBox->setVisible(false); } else { tbShowState = 1; ui->toolBox->setVisible(true); } } void MainWindow::on_butKeyboard_clicked() { ui->toolBox->setVisible(false); ui->teMain->setFocus(); kb.currentTtyPort = ui->cbPort->currentIndex(); kb.InitStyle(); } void MainWindow::on_cbPort_currentIndexChanged(const QString &arg1) { ui->lblPort->setText(arg1); } void MainWindow::on_cbBaud_currentIndexChanged() { QString setBaudStr; QByteArray setBaudByte; const char *setBaudChar; setBaudStr = "stty -F /dev/ttymxc" + QString(ui->cbPort->currentIndex()+48) + " speed " + ui->cbBaud->currentText() + "cs8"; setBaudByte = setBaudStr.toLatin1(); setBaudChar = setBaudByte.data(); ui->lblBaud->setText(ui->cbBaud->currentText()); if(ui->cbBaud->currentIndex()) { system(setBaudChar); qDebug() << "Set baud to 9600"; ui->teMain->append("Set baud to 9600"); } else { system(setBaudChar); qDebug() << "Set baud to 115200"; ui->teMain->append("Set baud to 115200"); } } void MainWindow::on_teMain_textChanged() { ui->teMain->moveCursor(QTextCursor::End); } void MainWindow::on_butClear_clicked() { ui->teMain->clear(); } void MainWindow::on_Reboot_valueChanged(int value) { if(value == 20) { qDebug() << "A1"; QProcess *newApp = new QProcess; qDebug() << "A2"; newApp->start("/home/DebugUART01 -qws"); qDebug() << "A3"; QApplication::exit(0); qDebug() << "A4"; } }