qvariant

Custom type in QVariant converts to empty string

拈花ヽ惹草 提交于 2020-04-08 12:36:12
问题 I'm writing a lexical scanner that generates a stream of tokens from some input. Those tokens have a type and a value . Since I'm using Qt I chose to store the token data as a QVariant . This works pretty well for token data that is of a non-custom type. Unfortunately, I have several custom types that are stored inside of tokens as well. The tokens have a toString() function that outputs a token description (for debugging), but for all tokens that have data of a custom type this function

Convert a QStandardItemModel to a QVariant

吃可爱长大的小学妹 提交于 2020-01-05 08:08:46
问题 I'm trying to send a QStandardItemModel-derived object to PythonQt, but I'm a little confused on how it needs to be sent. When I was using boost::python I had several controls like boost::noncopyable to ensure I wasn't recreating this object, but sharing it with python. I also had constructs to provide a boost shared pointer to python from inside python. class Scene : public boost::enable_shared_from_this<Scene>, public QStandardItemModel In PythonQt, however, I'm not sure what's available.

Using QTreeWidgetItems setData to store a QStackedWidget or QVariant

寵の児 提交于 2019-12-24 19:33:51
问题 I am trying to make a QTreeWidget such that each row contains a series of comboboxes. Depending on how the user interacts with the comboboxes I would like certain comboboxes to becomes line edits and some to become buttons. It was suggested here that a QStackedWidget would serve my needs and its done a pretty good job except now I need a way to alter the QStackedWidget that is next to the one that contains the combobox sending me an indexChanged signal. (Basically I want to change the

qVariantValue is “QT_DEPRECATED” - what is the replacement?

有些话、适合烂在心里 提交于 2019-12-23 18:11:05
问题 i need to convert Qt legacy code from 4 to 5.1 now i have compilation error in visual studio 2010 : SingleItem* item = qVariantValue<SingleItem*>(index.data()); gives me : .cpp(63): error C2065: 'qVariantValue' : undeclared identifier when i go to the header i see : #if QT_DEPRECATED_SINCE(5, 0) template<typename T> inline QT_DEPRECATED T qVariantValue(const QVariant &variant) { return qvariant_cast<T>(variant); } template<typename T> inline QT_DEPRECATED bool qVariantCanConvert(const

QVariant's Visitor pattern (without manual type testing and casting)

耗尽温柔 提交于 2019-12-18 05:20:32
问题 Does Qt's QVariant class has any existing (and convenient) Visitor pattern implementation? If not, is it possible to achieve something similar to boost::apply_visitor() , i.e. minimize the the duplication in regard to testing the type and casting? I want to achieve something along the following lines: /* I have a QVariant that can contain anything, including user types */ QVariant variant; /* But in my Visitor I'm interested only in ints and QStrings (for the sake of the example) */ struct

How can I cast a QVariant to custom class?

牧云@^-^@ 提交于 2019-12-18 03:22:31
问题 I'm developing a BlackBerry 10 mobile application using the Momentics IDE (native SDK). I have a listview which I want to handle its items click with C++ (I need to use C++ not QML). I can get the index path using the "connect" instruction, but I have problem with parsing a QVariant to a custom class ; Q_ASSERT(QObject::connect(list1, SIGNAL(triggered(QVariantList)), this, SLOT(openSheet(QVariantList)))); QVariant selectItem = m_categoriesListDataModel->data(indexPath); I tried to use the

QVariant with custom class pointer does not return same address

只谈情不闲聊 提交于 2019-12-14 03:42:07
问题 I need to assign a pointer to a custom class in qml using QQmlContext::setContextProperty() . Another qml object has Q_PROPERTY of the same type to retrieve it again. A simple test showed me that the conversion does not work like i thought. #include <QCoreApplication> #include <QDebug> #include <QMetaType> class TestClass { public: TestClass() { qDebug() << "TestClass()::TestClass()"; } }; Q_DECLARE_METATYPE(TestClass*) int main(int argc, char *argv[]) { QCoreApplication app(argc, argv);

QVariant comparison with own types working?

怎甘沉沦 提交于 2019-12-14 00:18:35
问题 Update I have created an qt bugticket hoping the documentation will be extended. Original Question Believing an Question from 2010 and the Qt Documentation, the operator==() doesn't work with custom types. Quote: bool QVariant::operator==(const QVariant & v) const Compares this QVariant with v and returns true if they are equal; otherwise returns false . QVariant uses the equality operator of the type() it contains to check for equality. QVariant will try to convert() v if its type is not the

How to convert QList<T> to QVariant?

妖精的绣舞 提交于 2019-12-13 16:13:34
问题 I can't find a way to convert my QList<T> to a QVariant . There's a constructor QVariant(const QList<QVariant> &val) , but no constructor for QList<T> , is it possible to convert directly a QList<T> ? 回答1: Example QList<int> ints{1,2,3}; QVariant var = QVariant::fromValue<QList<int>>(ints); 来源: https://stackoverflow.com/questions/44436386/how-to-convert-qlistt-to-qvariant

Iterating over a QVariant that is a QList<int>?

徘徊边缘 提交于 2019-12-13 05:07:11
问题 I'm using QObject's dynamic property to store information to be used in a Slot that can access said property. The sender is a QState with: myQState->setProperty("key", QList<int>(0, 1, 2)); I would like to convert the stored QVariant back to a QList so it can be iterated. The following code does not work (error C2440: QVariant can't be converted to QList with {[T=int]): QVariant vprop = obj->property("key"); QList<int> list = vprop; // < - - - - - - - - ERROR foreach (int e, list ) { qDebug()