1.其他小内容合集

来源:互联网 发布:hadoop2.6.0源码下载 编辑:程序博客网 时间:2024/05/17 03:38

使用控制台打开程式,需自动运行,可以使用计时器

runtimer = new QTimer();
connect(runtimer, SIGNAL(timeout()), this, SLOT(StartTest()));
runtimer->start();

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Little-Endian&Big-Endian

不同的CPU有不同的字节序类型,这些字节序是指整数在内存中保存的顺序。
最常见的有两种:
1. Little-endian:将低序字节存储在起始地址(低位编址)
2. Big-endian:将高序字节存储在起始地址(高位编址)
 
例子1:在内存中双字0x01020304(DWORD)的存储方式。 
内存地址 4000 4001 4002 4003 
   LE      04   03   02   01 
   BE      01   02   03   04 
注:每个地址存1个字节,每个字有4个字节。2位16进制数是1个字节(0xFF=11111111)。

 
例子2:如果我们将0x1234abcd写入到以0x0000开始的内存中,则结果为
    big-endian   little-endian
0x0000    0x12         0xcd
0x0001    0x23         0xab
0x0002    0xab         0x34
0x0003    0xcd         0x12

x86系列的CPU都是little-endian的字节序

+++++++++++++++++++++++++++++++++++++++++++++++++++++

限制lineEdit内容为数字
QRegExp regx("[1-9][0-9]+$");    set lineedit only number
QValidator *validator = new QRegExpValidator(regx, ui.lineEdit);
ui.lineEdit->setValidator(validator);

消除空格
EnVersion.replace(QRegExp("[\\s]+"), "");

+++++++++++++++++++++++++++++++++++++++++++++++++++++

二进制读取文件,读取后的内容可通过USB指令写入,虽然USB指令时使用unsigned char,但只要二进制格式不变既没问题
ifstream iFile
iFile.open(BIN.toStdString(), ios_base::binary);
if (!iFile)
{
pLog->OutLog("BIN File does not exits.");
return FALSE;
}

iFile.seekg(0, ios::end);
long len = iFile.tellg();
char *buf = new char[len];


iFile.seekg(0, ios::beg);//set to ios::beg , or will not read
iFile.read(buf, len*sizeof(char));
iFile.close();

0 0
原创粉丝点击