QT学习‘QMessageBox‘ has not been declared 。结构体序列化成hex字符串或字节数组和反过来

#include 或#include

#include 
void MainWindow::on_pushButton_clicked()
{
    bool result=false;
    QMessageBox::about(NULL,  "Result",  result?"PASS":"FAIL");
}
#include "mainwindow.h"
#include 
#include "ReadConfigFile.h"

#include 
#include 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    QMessageBox:: StandardButton result= QMessageBox::critical(NULL, "Error", "Try again?",QMessageBox::Yes|QMessageBox::No);
    switch (result)
    {
    case QMessageBox::Yes:
        qDebug()<<"Yes";
        break;
    case QMessageBox::No:
        qDebug()<<"NO";
        break;
    default:
        break;
    }


        //txCmdParam
        double max=10;
        double min=-10;

        const char section[]="Send1";
        char temp_buf[500]={0};
        int ret = ConfigGetKey(config_file, section, "Max", temp_buf);
        if(ret!=0) {       } //error

        memset(temp_buf,0,sizeof(temp_buf));
        ret = ConfigGetKey(config_file, section, "Min", temp_buf);
        if(ret!=0) {        } //error

        memset(temp_buf,0,sizeof(temp_buf));
        ret = ConfigGetKey(config_file, section, "txCmdParam", temp_buf);
        if(ret!=0) {        } //error

        char temp[]="7788899";
        ret = ConfigSetKey(config_file, section, "txCmdParam", temp);
        if(ret!=0) {        } //error




    return a.exec();
}

2为什么明明有实现,还提示

Controller.lib(LtePuschTxV2.obj):-1: error: LNK2019: 无法解析的外部符号 "class std::basic_string,class std::allocator > __cdecl bytesToHexString(unsigned char const *,int)" (?bytesToHexString@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBEH@Z),该符号在函数 "public: enum EMetaAppStatusCode __thiscall CLtePuschTxV2::Start(struct ERfTestCmdPuschTxV2 const &)" (?Start@CLtePuschTxV2@@QAE?AW4EMetaAppStatusCode@@ABUERfTestCmdPuschTxV2@@@Z) 中被引用

重构也不行,删除Debug文件夹也不行,可恶! 最后暂时先函数放在一个地方。其它地方用extern

3结构体序列化成hex字符串或字节数组和反过来

qDebug()<< "model_txCmdParam:" << QString::fromStdString(bytesToHexString((BYTE *)&txCmdParam,sizeof(ERfTestCmdPuschTxV2)));
#include 
typedef struct Test
{
	char name[2];
	int old;
}Test;

int main()
{
	Test t;
	t.old = 1;
	char temp[100] = { 0 };
	memcpy(temp, (char *)&t, sizeof(t)); //保存 ,是取地址后再转成char*
	t.old = 8;
	memcpy( (char *)&t, temp, sizeof(t));//恢复
    std::cout <<" old="<

你可能感兴趣的:(QT学习‘QMessageBox‘ has not been declared 。结构体序列化成hex字符串或字节数组和反过来)