QT

来源:互联网 发布:公司招聘淘宝直播主播 编辑:程序博客网 时间:2024/05/17 03:58

 

//1 String to int  Qstring str="5E";    bool ok;    int dec=str.toInt(&ok,10); //failed   int hex =str.toInt(&ok,16); //ok //2 Qt: 给Widget设置背景图片    //在Widget构造函数里面    this->setAutoFillBackground(TRUE);    QPalette palette = this->palette();    palette.setBrush(QPalette::Window, QBrush(QPixmap("D:/2014/ASM570EX/build-ASM570/debug/PPMM/M1.jpg")));    this->setPalette(palette);//3 QT使用资源文件显示图片   1. Add new - Qt - Qt Resource file  2. picture.qrc 右键 open in Editor  3. Add file  4. Button   Icon选择Picture,然后geometry Width*Height //4 QT project add new projectfes\src\vxd\asmtt1     copy card.pri,card.h,card.cpp --> rfid.pri,rfid.h,rfid.cpp2     fes\vxd\TT_ASMTT_CARD              copy directory to TT_ASMTT_RFID3     vxd.pro -- add TT_ASMTT_RFID4     rfid_global.h --  modify micro #define......RFID    //5 qt的connect与socket的connect冲突      //在使用connect的类后面加上public QObject,因为connect是在QObject里面实现的。XXX.hprivate:Thread *pthread;private slots:    void getdata(QString barcode);    XXX.cppconnect(pthread, SIGNAL(hasdata(QString)), this, SLOT(getdata(QString))); //报错 //6 一个继承于QThread的类class Thread : public QThresad{   _OBJECT  //check this exist or not    //不用重写start()方法, 可以命名一个另外相似的方法mystart()public:void mystart(); //stopped=truesignals:void hasdata(QString str);protected:     void run(); //重写run方法 while(stopped)volatile bool stopped;};Thread *_pthread = new Thread();_pthread->mystart();_pthread->start(); //线程已经开始执行重写的run()方法了_pthread->run(); //不用显式调用run()!!//7 QT信号与槽在不能连接的问题class Glass: public QObject, public Cup //QObject放在前面{ Q_OBJECT //这个必须有public: Glass();~Glass();  //... };connect(_pthread, SIGNAL(hasdata(QString)), this, SLOT(getdata(QString))); //_pthread 对象要存在,即要先new出来.

int value=220060;QString sx = QString::number(value, 16).toUpper(); //"35b9c" //QString里面的一个静态方法//前面补0//"00035b9c"------------------------------------------------------------------------------Sleep(100); //will block!!qlonglong dtBegin = QDateTime::currentMSecsSinceEpoch();while(i<1000) //1 second{    qlonglong dtNow = QDateTime::currentMSecsSinceEpoch();    i = dtNow - dtBegin;    QApplication::processEvents(); //no block!!    if(status == true) //finish flag    {        break;    }}------------------------------------------------------------------------------------DosthWidget *pDosth = NULL; //全局this指针DosthWidget::DosthWidget(QWidget *parent) : QWidget(parent), ui(new Ui::DosthWidget){    ui->setupUi(this);    pDosth = this;}static void DosthWidget::process_trace() //静态成员方法{//use pDosth//pDosth->somefunction(); //普通成员方法?}------------------------------------------------------------------------------------map可以当数组使用std::map<int, long long> _mTime;_mTime[0] = 0;_mTime[1] = QDateTime::currentMSecsSinceEpoch(); _mTime[2] = QDateTime::currentMSecsSinceEpoch(); //QDateTime里面的一个静态方法//......using namespace std; //use in .cpp files instand of in .h filespair<std::string, long long> StatusTime();pair<std::string, long long> StatusTime(){string value = "01";    long long nowtime = _mTime[2];    return pair<string, long long>(value, nowtime);}pair<string, long long> pTime = StatusTime();pTime.firstpTime.second------------------------------------------------------------------------------------

0 0