Qt QList<T> casts and node_copy

513 views Asked by At

I catch an error and don't know how to fix it. I am doing combobox selector for available SQLDrivers (providers).

Header

#include "QObject"
#include "QString"
#include "QList"
#include "QPointer"

class TProvider;
typedef const TProvider * const TProviderPointer;

class TProvider
{
    public:
        QString name;
        QString driverName;

        TProvider(QString name, QString driverName);
        static const QList<TProviderPointer> getAvailableProviders();
        static TProviderPointer getProvider(int id);
};

TProviderPointer MySQLProvider = new TProvider("MySQL", "QMYSQL");
TProviderPointer IBProvider = new TProvider("Interbase", "QIBASE");

CPP. Here I create two const pointers to const Providers (TProviderPointer) (enumerating avaliable drivers). And I have a method, wich return const QList.

#include "tprovider.h"

TProvider::TProvider(QString name, QString driverName):
    name(name), driverName(driverName)
{
}

const QList<TProviderPointer> TProvider::getAvailableProviders()
{
    QList<TProviderPointer> list;
    list.append(MySQLProvider);
    list.append(IBProvider);

    return list;
}

TProviderPointer getProvider(int id)
{
    switch(id){
        case 0:
            return MySQLProvider;
        case 1:
            return IBProvider;
    }
}

when I use this

const QList<TProviderPointer> list = TProvider::getAvailableProviders();
foreach (TProviderPointer provider, list) {
    ui->eprovider->addItem(provider->name);
}

I get and error pointing to qlist.h and line const QList<TProviderPointer> list = TProvider::getAvailableProviders(); -> C2440 TProviderPointer * to void * line:

Q_INLINE_TEMPLATE void QList<T>::node_copy(Node *from, Node *to, Node *src)

Do I have any copy operation in usage? How can I fix this? Thanks.

1

There are 1 answers

0
Nejat On BEST ANSWER

I think the problem is with your typedef. const TProvider * const is a pointer to const TProvider but in your code your are making new instances of TProvider at runtime. Also you can read in the Qt documentation about QList that :

QList's value type must be an assignable data type.

So you should have a pointer to TProvider and your typedef should be like :

typedef const TProvider * TProviderPointer;