How to cast enums which are using QFlags and QList?
来源:互联网 发布:手机版抢购软件神器 编辑:程序博客网 时间:2024/06/04 18:06
question:http://qt-project.org/forums/viewthread/13855
class Locale {public: enum ENUMList { ... }; enum ENUMFlags { ... }; Q_DECLARE_FLAGS(ENUMFlag, ENUMFlags) QList<Locale::EnumList> list(); ENUMFlag giveMeFlags();}; class WrapLocale {public QList<Locale::EnumList> returnList() { return m_locale.list(); } Locale::ENUMFlag returnFlags() { return m_locale.giveMeFlags(); } private: Locale m_locale;}
Qt 的QFlags类型2009-03-12 10:07Qt里面定义了大量的枚举类型,有些类型的内部元素可以并列的。例如Qt::AlignmentFlag类型,包括The horizontal flags are:Qt::AlignLeft0x0001Aligns with the left edge.Qt::AlignRight0x0002Aligns with the right edge.Qt::AlignHCenter0x0004Centers horizontally in the available space.Qt::AlignJustify0x0008Justifies the text in the available space.The vertical flags are:ConstantValueDescriptionQt::AlignTop0x0020Aligns with the top.Qt::AlignBottom0x0040Aligns with the bottom.Qt::AlignVCenter我们可以用Qt::AlignTop | Qt::AlignLeft 来表示左上角。假设一个函数接受位置作为参数,那么一般来说我们需要把这个函数的参数定义成int类型。这样就造成传递给函数的参数非法(132),但是函数却不能静态检查出来。把错误留给了运行阶段。Qt定义了一个Flag的类,对于一个enum类型,通过声明 Q_DECLARE_FLAGS ( Flags, Enum ) 就会定义一个新的类型Flags。上面的函数就可以用Flags做参数了。Q_DECLARE_FLAGS ( Flags, Enum ) 扩展成了 typedef QFlags<Enum> Flags;例如:Qt::AlignmentFlag 就定义了Qt::Alignment作为它的Flags。在使用的时候我们直接定义setAlignment(Qt::Alignment) 的函数就可以接受 Qt::AlignTop | Qt::AlignLeft 这样的参数了。其他的操作和参考Qt文档 qflags。
http://blog.csdn.net/dbzhang800/article/details/6734273
- How to cast enums which are using QFlags and QList?
- How to check which responsiblity we are using
- OpenVMS - How to Find which Processes Are Using a Specific Pagefile
- Openvms-C-Sourcecode- How to Find which Processes are using a specific pagefile or swapfile
- How to determine which version of .net framework are installed
- How to know the port which process is using
- initrd, initramfs, which I need and how to use???
- How to reference JSF managed beans which are provided in a JAR file?
- How to clear the views which are held in the ListView's RecycleBin?
- given two directory trees how to find which files are the same?
- JWT vs JWS vs JWE - What They Are and When to Use Which
- The servlets named [] and [] are both mapped to the url-pattern [/] which is not permitted
- How to find which w3wp.exe belongs to which application pool and Find correct w3wp ProcessId for Web
- How to automate Excel using MFC and worksheet functions
- How to make dll and lib using bakefile.
- How to Draw Waveform While Recording Using NAudio and WPF
- How to develop and package Android Wear App using Eclips
- how to start and stop android service by using adb
- 亚马逊云服务6年来第19次降价
- (转)C++中extern “C”含义深层探索
- 并行操作为什么无法执行
- Android中android:visibility的3中属性的剖析
- Wcf 安全性 之 None
- How to cast enums which are using QFlags and QList?
- centos 6.1 samba文件共享服务器 子目录不可见 共享问题
- WinCE中将调试信息写入文件的方法[转载]
- ./sqlplusSP2-0667: Message file sp1<lang>.msb not found。SP2-0750: You may need to set ORACLE_HOME t
- IE6 下图片不能显示的问题解决
- flv格式视频播放
- android 之view与viewgroup
- 什么是REST架构
- java中的监听者模式