qt 中枚举enum的使用方法 | 您所在的位置:网站首页 › enum使用 › qt 中枚举enum的使用方法 |
今天突然想着 感觉好久没用过枚举这个enum这个函数了 就在qt程序中写了个enum变量定义 发现用不了,百度 记录下。才知道qt中使用enum和c和c++中还有点不一样 .h中定义 enum triggerMode { triggerAuto = 1 , triggerSignalOne , triggerContinue } ;.cpp 中 #include // 添加一个定义 // 在函数外面添加如下 QMetaObject enumTriggerMode = MainWindow::staticMetaObject; int index = enumTriggerMode.indexOfEnumerator("triggerMode"); QMetaEnum metaEnum = enumTriggerMode.enumerator(index); // 好了 这样就可以调用了 qDebug("%s",metaEnum.key(ui->comboBox_autoTrigger->currentIndex()) ); qDebug("%d", metaEnum.value(ui->comboBox_autoTrigger->currentIndex())); // 感觉还是有点麻烦下面在读一段qcustomplot的源代码 他们怎么使用enum的吧 /*! Defines the different units in which the image resolution can be specified in the export functions. \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered */ enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) }; extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace } // end of namespace QCP Q_DECLARE_METATYPE(QCP::ResolutionUnit)有空还是要多看看源代码 才能更好的提高自己 |
CopyRight 2018-2019 实验室设备网 版权所有 |