Qt-interest Archive, February 2008
Complex QVariant problem
Message 1 in thread
This is with Qt 4.3.2:
I have the following typedefs:
> typedef QMap<QString, QVariant> VMap;
> typedef QList<VMap> VMapList;
and the following code:
> VMap transaction_data =
> RunQuery::Query2VMap
> (runquery_->select_sql("Transactions",
> where, where_data));
>
> VMapList files_data =
> RunQuery::Query2VMapList
> (runquery_->select_sql("Files",
> where, where_data));
>
> VMap transaction;
> transaction["transaction"] = transaction_data;
> transaction["files"] = files_data;
g++ is complaining about the final assignment as follows:
> error: no match for âoperator=â in âtransaction. QMap<Key, T>::operator[]
> [with Key = QString, T = QVariant](((const QString&)(& QString(((const
char*)"files")))))
> = files_dataâ
> /usr/local/Trolltech/Qt-4.3.2/include/QtCore/qvariant.h:209:
> note: candidates are: QVariant& QVariant::operator=(const QVariant&)
Now, given that I'm trying to assign a QList<QMap<QString, QVariant> >
to a QVariant, I can't see what the problem is, as the QVariant docs
indicate that QMap<QString, QVariant> and QList<QVariant> are both
valid QVariants.
Can anyone see what's wrong here ?
--
[ signature omitted ]
Message 2 in thread
Hi, QVariant has a constructor which takes "QMap<QString, QVariant>"
but no constructor which takes "QList< QMap<QString, QVariant> >" so
use QVariant::fromValue().
--
[ signature omitted ]
Message 3 in thread
Hi Stephen,
The problem is that you can't store a QList<QMap<QString, QVariant>> in a
QVariant. You can store a QList<QVariant> in it, but that is a different
type.
You need to store the files_data in QList<QVariant> instead for this to work.
Bo.
On tirsdag den 26. Februar 2008, Stephen Collyer wrote:
> This is with Qt 4.3.2:
>
> I have the following typedefs:
> > typedef QMap<QString, QVariant> VMap;
> > typedef QList<VMap> VMapList;
>
> and the following code:
> > VMap transaction_data =
> > RunQuery::Query2VMap
> > (runquery_->select_sql("Transactions",
> > where, where_data));
> >
> > VMapList files_data =
> > RunQuery::Query2VMapList
> > (runquery_->select_sql("Files",
> > where, where_data));
> >
> > VMap transaction;
> > transaction["transaction"] = transaction_data;
> > transaction["files"] = files_data;
>
> g++ is complaining about the final assignment as follows:
> > error: no match for âoperator=â in âtransaction. QMap<Key, T>::operator[]
> > [with Key = QString, T = QVariant](((const QString&)(& QString(((const
>
> char*)"files")))))
>
> > = files_dataâ
> > /usr/local/Trolltech/Qt-4.3.2/include/QtCore/qvariant.h:209:
> > note: candidates are: QVariant& QVariant::operator=(const QVariant&)
>
> Now, given that I'm trying to assign a QList<QMap<QString, QVariant> >
> to a QVariant, I can't see what the problem is, as the QVariant docs
> indicate that QMap<QString, QVariant> and QList<QVariant> are both
> valid QVariants.
>
> Can anyone see what's wrong here ?
--
[ signature omitted ]
Message 4 in thread
Bo Thorsen wrote:
> Hi Stephen,
>
> The problem is that you can't store a QList<QMap<QString, QVariant>> in a
> QVariant. You can store a QList<QVariant> in it, but that is a different
> type.
>
> You need to store the files_data in QList<QVariant> instead for this to work.
Bo
Yes, I see the problem now. I've sorted it out.
I'm translating the code from Perl and sometimes
its lack of typing makes it a little too easy to
screw up this kind of logic.
Thanks.
--
[ signature omitted ]