2013-02-21 50 views
7

khai trong tập tin tiêu đềQVariant :: QVariant (Qt :: GlobalColor)' là tin

QColor dialogBoja, dialogBoja1; 

tập tin cpp

dialogBoja = postavke.value("boja", Qt::black).toString(); 
//postavke means settings 
dialogBoja1 = postavke.value("boja1", Qt::white).toString(); 

Như tôi đã nói trên tiêu đề, khi tôi cố gắng biên dịch này trong Qt5 Tôi gặp lỗi: QVariant :: QVariant (Qt :: GlobalColor) 'là riêng

Cách giải quyết vấn đề này.

Trả lời

9

Bạn cần tạo đối tượng QColor một cách rõ ràng. Điều này sẽ làm việc:

dialogBoja = postavke.value("boja", QColor(Qt::black)).toString(); 

Lý do cho điều này được giải thích trong phần đầu:

// 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. 
3

Hình như họ muốn ly hôn QVariant từ các module QtGui, như QColor, và loại bỏ constructor rằng trong 5.0. Một số cú pháp được giải thích here.

Because QVariant is part of the QtCore library, it cannot provide conversion functions to data types defined in QtGui, such as QColor, QImage, and QPixmap. In other words, there is no toColor() function. Instead, you can use the QVariant::value() or the qvariant_cast() template function.

Các vấn đề liên quan