当前位置: 代码迷 >> QT开发 >> 关于Qt 5.3中“comBox->addItem(); ”函数解决方法
  详细解决方案

关于Qt 5.3中“comBox->addItem(); ”函数解决方法

热度:877   发布时间:2016-04-25 03:00:51.0
关于Qt 5.3中“comBox->addItem(); ”函数
就是想实现组合框下拉菜单选择不同颜色显示的功能,这当中使用了comBox->addItem();函数,代码如下:
02. QComboBox *comBox;  
03. QPixmap pix(16,16); //创建绘图设备     
04. QPainter painter(&pix);//创建一个画笔      
05. painter.fillRect(0,0,16,16,Qt::black);      
06. comBox->addItem(QIcon(pix),tr("黑色"),Qt::black);      
07. //红色      
08. painter.fillRect(0,0,16,16,Qt::red);      
09. comBox->addItem(QIcon(pix),tr("红色"),Qt::red);      
但是在编译的时候报错:1)C:\Qt\Qt5.3.0\5.3\mingw482_32\include\QtCore\qvariant.h:481: error: 'QVariant::QVariant(Qt::GlobalColor)' is private
     QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE;
       
2)D:\User\paint\mainwindow.cpp:192: error: within this context
     comboBox->addItem(QIcon(pix),tr("黑色"),Qt::black); 
请问这是为何?这段代码应该是很成熟的,不应该再会出现这种错误。
                                                        
------解决思路----------------------
// These constructors don't create QVariants of the type associcated
// with the enum, as expected, but they would create a QVariant of
// type int with the value of the enum value.
// Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for
// example.
  相关解决方案