qt 中枚举enum的使用方法 您所在的位置:网站首页 enum使用 qt 中枚举enum的使用方法

qt 中枚举enum的使用方法

2024-06-24 03:07| 来源: 网络整理| 查看: 265

今天突然想着 感觉好久没用过枚举这个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 实验室设备网 版权所有