I am trying to port a Qt application to C++ using STL. What is the equivalent of QVariant in C++? QVariant can store any data type - a container that holds heterogenous - different types of objects. However, I have to port this application to C++. What is the equivalent of QVariant in C++?
What is the equivalent of QVariant in C++?
4.9k Views Asked by dexterous At
2
There are 2 best solutions below
0
Leon Timmermans
On
Starting in C++17, there is std::any (may contain a value of any copyable type) and std::variant (may contain a value of any of the given types). These will be supported out of the box in GCC 7, Clang 4.0 and Visual C++ 2017.
Neither of these is entirely equivalent (for example they don't support converting the internal value), but they will allow you to do most of what QVariant does.
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in QT
- C++ template using pointer and non pointer arguments in a QVector
- Using QPointer and QObject::connect with C++11
- qt How to style a QToolBar > QToolButton overflow button?
- Qt - Repeatedly write at beginning of file
- C++ Mongodb driver, not working
- deletion and cleanup of worker thread in Qt crashes
- How to drap item from QTableView to QPushButton?
- get image type from qimage
- C++ QT Getting part from QString
- How to connect a destroyed signal of C++ object from QML?
- How to get shader version from QOpenGLShader?
- Size of Qt QRadioButton able to get smaller, but not larger than default
- error WinSock.h has already been included Boost Windows Qt
- How to call a non-class member function with pointers as parameters with QtConcurrent::run?
- What is the difference between MinGW SEH and MinGW SJLJ?
Related Questions in STL
- C++ using std::vector across boundaries
- Downcast from a container of Base* to Derived* without explicit conversion
- C++ Custom std::map<> key class causing memory violation
- How to get rid of the ".\r\n" characters appended to the error message from FormatMessageA?
- What is the equivalent of boost::system::error_code with GetLastError in C++ Standard Library?
- How to insert data into map where one parameter is an object?
- C++11 template instance wrapping vector makes error
- No viable conversion std::weak_ptr to std::shared_ptr for method call
- syntax: doing binary_search (STL) for sorted vector of pointers to struct
- Linker error using VS 2015 RC, can't find symbol related to std::codecvt
- Pass vector of char vectors to char**
- Android NDK / Exceptions?
- How to insert data into nested map in c++?
- Which STL container(s)/algorithm(s) could I use to solve this?
- Is there a way to iterate over at most N elements using range-based for loop?
Related Questions in QTCORE
- Qt - disconnection from BLE device
- What is QList's maximum size?
- PyQt Window Focus on right-click
- QThread::wait() does not return without using direct connection
- Ncurses and Qt Interoperability
- QProcess exits the application after calling QProcess.start()
- QTextStream::readLine(): invalid return value
- Thread sending http request using Qt
- Getting the name of sub class within super class in Qt
- Inheriting subclasses can not use Q_OBJECT
- Global object and creation order
- QObject: cannot open include file 'QtCore/qobjectdefs.h'
- Questions about Qt internationalization
- String to float conversion and formatting
- What happens with Qt signals when the receiver is busy?
Related Questions in QVARIANT
- Snapping in grid using qt
- Qt Json serialization
- QVariant conversion to QPainterPath
- Make QGenericArgument/Q_ARG from QVariant
- Qt retrieve QFlags form QVariant
- How QVariant Works Internally?
- no match for 'operator[]' (operand types are 'QVariant' and 'const char [2]') QVariant/QVariantMap
- Converting QList to QVariant
- Convert QPair to QVariant
- Qt DBus property convert to map
- Cannot set QVariantMap as QML property
- What is the equivalent of QVariant in C++?
- From QVariant to Integer and String
- And so a QVariant instantiation silently registeres a (previously declared) metatype
- How to create a QVariant-based generic model?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The equivalent in C++ is called
QVariant.Semi-joke aside, it is probably the closest to union, but QVariant is so much more than that; meta types, CoW, etc.
Actually, sharing implicitly is forbidden these days in STL, so that is another reason why you would not find anything like this off-hand.
I would suggest to make notes to yourself what functionality exactly you need from a QVariant and make a judgement call whether it is actually worth dropping QtCore.
This is just a friendly reminder from the documentation:
However, since C++11 types with constructors and destructors are allowed. You have another question in here to ask from yourself:
To be fair, you could also look into the following boost variants below, but then you end up using boost instead of QtCore after the porting.
This is another judgement call for yourself. They are not replacements for each other, neither technically, nor compatibility wise.
Boost in this case is a build time dependency, while QtCore is a runtime. Qt would guarantee binary (and source) compatibility during the life cycle of the same major version, while boost may not do the same for such a long period as QtCore does.
Either way, none of these options are pure
STLsolutions in the end of the day the way I think you wanted it to.Boost.Any
Boost.Variant