#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this,SIGNAL(info(QString ,int )),this,SLOT(showInfo(QString ,int )));
qDebug()<<"num = " << APPCONFIG->getNums();
}
MainWindow::~MainWindow()
{
delete ui;
}
SingleMode *SingleMode::getInsteast()
{
static SingleMode single;
return &single;
}
int SingleMode::getNums()
{
m_num ++;
return m_num;
}
void SingleMode::run()
{
m_stopflag = false;
emit info("start:---CThread_child---");
while (m_stopflag == false) {
QThread::msleep(1000);
m_num ++;
qDebug()<< "Child: Is running, num = " << m_num;
}
}
SingleMode::SingleMode()
{
m_num = 0;
}
SingleMode::~SingleMode()
{
m_num = 0;
}
void MainWindow::on_pushButton_clicked()
{
emit info("Btn1:---Start theread ---",0);
APPCONFIG->start();
}
void MainWindow::on_pushButton_2_clicked()
{
emit info("Btn2:---Stop thread ---",1);
APPCONFIG->stop();
}
void MainWindow::showInfo(QString info, int flag)
{
QString tempinfoshow;
QString tempstr;
if(flag == 0)
tempinfoshow = "<span style='color:blue;'>%1</span>";
else
tempinfoshow = "<span style='color:red;'>%1</span>";
if (ui->textBrowser->document()->blockCount() >= 2000) ui->textBrowser->clear();
QTime curtime = QTime::currentTime();
tempstr = QString("info:[%1]<br>").arg(curtime.toString("hh:mm:ss"));
tempstr += info;
tempinfoshow = tempinfoshow.arg(tempstr);
ui->textBrowser->append(tempinfoshow);
}