1

I'm doing auto data = combobox->currentData().value<QPair>(); but the compiler complains with:

[ 48%] Building CXX object src/CMakeFiles/mudlet.dir/dlgProfilePreferences.cpp.o
/home/vadi/Programs/Mudlet/mudlet/src/dlgProfilePreferences.cpp: In lambda function:
/home/vadi/Programs/Mudlet/mudlet/src/dlgProfilePreferences.cpp:420:81: error: no matching function for call to ‘QVariant::value()’
                 auto data = script_preview_combobox->currentData().value<QPair>();
                                                                                 ^
In file included from /home/vadi/Programs/Qt/5.9/gcc_64/include/QtCore/QVariant:1:0,
                 from /home/vadi/Programs/Mudlet/mudlet/cmake-build-debug/src/ui_profile_preferences.h:12,
                 from /home/vadi/Programs/Mudlet/mudlet/src/dlgProfilePreferences.h:27,
                 from /home/vadi/Programs/Mudlet/mudlet/src/dlgProfilePreferences.cpp:25:
/home/vadi/Programs/Qt/5.9/gcc_64/include/QtCore/qvariant.h:351:14: note: candidate: template<class T> T QVariant::value() const
     inline T value() const
              ^
/home/vadi/Programs/Qt/5.9/gcc_64/include/QtCore/qvariant.h:351:14: note:   template argument deduction/substitution failed:
src/CMakeFiles/mudlet.dir/build.make:806: recipe for target 'src/CMakeFiles/mudlet.dir/dlgProfilePreferences.cpp.o' failed

As far as I see, my call is lining up with template<class T> T QVariant::value() - what's wrong?

Vadim Peretokin
  • 2,221
  • 3
  • 29
  • 40

1 Answers1

5

QPair is a template class and your code for getting the value from the variant does not fully describe the type.

First you need to know what two types your QPair describes. Then you must use the following code to extract it (changing the QString and int to your pairs data types):

auto pair = combobox->currentData().value<QPair<QString, int> >();
aatwo
  • 948
  • 6
  • 12