The Model/View framework uses QVariant to pass data between the Model and the View. This works fine for Qt's own data types, but I want to pass my own data type to the view (the delegate knows how to handle my custom data).

I have subclassed QBitArray and registering MyBitArray using the following code. It just works fine:
Qt Code:
  1. Q_DECLARE_METATYPE(MyBitArray);
To copy to clipboard, switch view to plain text mode 

Now I want to pass two of these custom BitArrays without using two columns (ModelIndeces), as they get edited together (data and mask), so I tried
Qt Code:
  1. typedef QPair<MyBitArray, MyBitArray> MyBitArrayPair;
  2. Q_DECLARE_METATYPE(MyBitArrayPair);
To copy to clipboard, switch view to plain text mode 
and
Qt Code:
  1. class MyBitArrayPair
  2. {
  3. public:
  4. MyBitArrayPair() {}
  5. MyBitArray first;
  6. MyBitArray second;
  7. };
  8. Q_DECLARE_METATYPE(MyBitArrayPair);
To copy to clipboard, switch view to plain text mode 

The compiler does not complain anymore about
Qt Code:
  1. MyBitArrayPair pair = value.value<MyBitArrayPair>();
To copy to clipboard, switch view to plain text mode 
but still complains about
Qt Code:
  1. case Qt::EditRole: return MyBitArrayPair(x.data(), x.mask());
To copy to clipboard, switch view to plain text mode 
with the following error message:
"error: conversion from 'MyBitArrayPair' to non-scalar type 'QVariant' requested"
There is a constructor for MyBitArrayPair(first, second) that I omitted here.

What am I doing wrong? How can I pass custom classes using QVariant?

Thanks in advance,
-Jens