/*
statusBar()->setMinimumSize(600,400);
statusBar()->setMinimumWidth(600);
statusBar()->setMinimumHeight(400);
*/
//ui-statusbar设置
ui->statusbar->setMinimumSize(600,400);
ui->statusbar->setMinimumWidth(600);
ui->statusbar->setMinimumHeight(400);
setMinimumSize(600,400);
//setMinimumWidth(600);
//setMinimumHeight(400);
status->setText(time + QString(" ") + message);
ui->statusbar->addWidget(status);
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
ConfigDialog::ConfigDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::ConfigDialog)
{
ui->setupUi(this);
QStringList list1 = QStringList(getLocalHostIpAddress());
ui->combLocalIP ->addItems(QStringList(list1));
}
QString ConfigDialog::getLocalHostIpAddress(){
QString strIpAddress;
QList<QHostAddress> ipAddressList = QNetworkInterface::allAddresses();
//获取第一个本主机的IPv4地址
int nListSize = ipAddressList.size();
for(int i = 0;i < nListSize; i++){
if(ipAddressList.at(i) != QHostAddress::LocalHost &&
ipAddressList.at(i).toIPv4Address()){
strIpAddress = ipAddressList.at(i).toString();
break;
}
}
//如果没找到,则以本地IP地址位IP
if(strIpAddress.isEmpty()){
strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
}
return strIpAddress;
}
QStringList list1 = QStringList(getLocalHostIpAddress());
ui->combLocalIP ->addItems(QStringList(list1));
QString str = ui->textEdit->text();
QString my_local_ip = ui->combLocalIP->currentText();
#pro中
QT += charts
//HexDataProess.cpp
#include "iostream"
#include "QString"
#include
#include
#include
#include
#include
#include
#include "HexDataProcess.h"
QList<double> REM(QString data)
{
QList<double> Orignal;
QList<QString> Changing; //储存6字节分割的数据
QList<double> result;
int countflag = 0;
while(countflag < data.size()) //将数据导入链表
{
QString rem;
rem = data.mid(countflag,6);
//qDebug()<<"数据组包"<
Changing.append(rem);
countflag+=6;
}
QString rem; //将链表内的数据依次转换
for(int i = 0 ; i < Changing.size(); i++)
{
//qDebug("%d",i);
rem=Changing[i];
int count;
qint8 array[6];
qint64 num[24]={0};
int h=23;
for(int b = 0 ; b < 6 ; b++ )
{
array[b]=rem.at(b).unicode(); //返回指定位置字符的ascii值
}
for(int l=5;l>=0;l--) //获取补码转入整形数组中
{
if(array[l]>57) //属于abcde
{
if( array[l] > 64 && array[l] < 71 ) //大写
count = array[l] - 55;
else
count = array[l] - 87; //小写
for(int j = 0 ; j < 4 ; j++) //将数据转换为二进制
{
num[h--] = count % 2;
count /= 2;
}
}
else //属于0-9
{
count = array[l] - 48;
for(int j = 0 ; j < 4 ; j++)
{
num[h--] = count % 2;
count/=2;
}
}
}
if(num[0]==1) //如果是负数,需将补码转为原码
{
for(int i=23;i>0;i--) //减一
{
if(num[i] == 1)
{
num[i] = 0;
break;
}
else
{
num[i]=1;
}
}
for(int i=23;i>0;i--) //取反
{
if(num[i]==1)
num[i]=0;
else
num[i]=1;
}
}
double sum=0; //得到采样值
for(int i=23;i>0;i--)
{
for(int l = 0 ; l< 23 - i ; l++)
{
num[i] *= 2;
}
sum += num[i];
}
if(num[0] == 1) //判断数据的正负
sum *= (-1);
//qDebug()<<"原始数据大小"<
result.append( sum / ADC_24_MAX * voltage);
Orignal.append(sum);
}
return result;
}
//HexDataProess.h
#ifndef HEXDATAPROCESS_H
#define HEXDATAPROCESS_H
#include "QString"
#include
#define ADC_24_MAX 8388607
#define voltage (2.5)
QList<double> REM(QString date);
#endif // HEXDATAPROCESS_H
QT的线程是为了,防止一直在一个线程中而不执行其他应用
#include
class 类名 : public QThread{};
#include "testthread.h"
#include "ui_testthread.h"
#include "unistd.h"
#include
TestThread::TestThread(QWidget *parent) :
QWidget(parent),
ui(new Ui::TestThread)
{
ui->setupUi(this);
connect(ui->pushButton,&QPushButton::clicked,this,&TestThread::on_pushButton_click);
}
TestThread::~TestThread()
{
delete ui;
}
void TestThread::showInfo(){
int i=0;
for(;;){
qDebug() << i;
ui->lineEdit->setText(QString::number(i++));
sleep(1);
}
}
void TestThread::on_pushButton_click(){
std::thread my_thread(&TestThread::showInfo,this);
my_thread.detach();
}
开启线程的方法
void start(QThread::Priority priority = InheritPriority)
退出线程
void quit()
或void exit(int returnCode = 0)
这个exit要退出时在时间片上的线程退出不了,要跟bool wait(unsigned long time = ULONG_MAX)
进行配合
终止线程的方式(不推荐)
void terminate()
不安全的函数,一般要和wait函数配合
使用一个自定义类继承QThread来重写run方法
//my_thread.cpp
#include
#include
void My_Thread::run(){
int i = 0;
for(;;){
emit threadSignal(i++);
qDebug() << i;
this->sleep(1);
if(i > 10){ //大于10退出循环
break;
}
}
}
My_Thread::My_Thread(QObject *parent):QThread(parent){
}
My_Thread::~My_Thread(){
//解构函数
}
//自定义ui界面(这里是继上个页面的ui)
#include "testthread.h"
#include "ui_testthread.h"
#include "unistd.h"
#include
void TestThread::on_pushButton_click(){
my_thread->start();
}
TestThread::TestThread(QWidget *parent) :
QWidget(parent),
ui(new Ui::TestThread)
{
ui->setupUi(this);
my_thread = new My_Thread(this);//my_thread 在.h中申明
connect(ui->pushButton,&QPushButton::clicked,this,&TestThread::on_pushButton_click);
connect(my_thread,&UdpThread::threadSignal,[=](int val){
ui->lineEdit->setText(QString::number(val));
});
}
TestThread::~TestThread()
{
delete ui;
}
TestThread::~TestThread()
{ //显示使用的ui cpp文件的解构函数
delete ui;
my_thread->exit(); //线程退出
my_thread->wait(); //线程等待
}