Russian Qt Forum
Ноябрь 25, 2024, 13:17 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: Не могу засунуть свой тип в QList....  (Прочитано 3756 раз)
lolbla2
Гость
« : Февраль 25, 2013, 06:43 »

Создал свой класс:

channel.h
Код
C++ (Qt)
class Channel
{
public:
   Channel(){}
   Channel(const Channel &other){}
   ~Channel(){}
   Channel(QString provider, QString title, QString thumbnail, QString category, int id, int catId);
 
   //getters
   QString getProvider() const {return m_provider;}
   QString getTitle() const {return m_title;}
   QString getThumb() const {return m_thumbnail;}
   QString getCategory() const {return m_category;}
   int getId() const {return m_id;}
   int getCategoryId() const {return m_categoryId;}
private:
   QString m_provider;
   QString m_title;
   QString m_category;
   QString m_thumbnail;
   int m_id;
   int m_categoryId;
};
 
Q_DECLARE_METATYPE(Channel);
Q_DECLARE_METATYPE(QList<Channel>);
 
 

channel.cpp

Код
C++ (Qt)
#include "channel.h"
#include <QDebug>
 
Channel::Channel(QString provider, QString title, QString thumbnail, QString category, int id, int catId)
{
   m_provider = provider;
   m_title = title;
   m_thumbnail = thumbnail;
   m_category = category;
   m_id = id;
   m_categoryId = catId;
}
 
почему при попытке засунуть его в QList<Channel>  в списке данные превращаются в мусор?

Засовываю вот так:

Код
C++ (Qt)
QList<Channel> channels;
   for(int i=0; i<ls.size(); i++)
   {
       Channel c("ThickTV",ls.at(i).toMap()["name"].toString(),"...","Все",i,0); // ls.at(i).toMap()["name"].toString() -  данное преобразование  возвращает   вполне нормальное название канала, проверял
       channels.append(c);
   }
   qWarning()<< "size " <<  channels.size();
 
for(int i=0; i<channels.size(); i++)
   {
       qWarning() << channels[i].getProvider() << channels[i].getTitle() << channels[i].getThumb() <<
                     channels[i].getCategory() << channels[i].getCategoryId() << channels[i].getId();
   }
 

Получаю вывод:

[09:42:22] Warning: size  156
[09:42:22] Warning: "" "" "" "" 147339080 147466176
[09:42:22] Warning: "" "" "" "" 147466080 147466208
[09:42:22] Warning: "" "" "" "" 147339080 147466176
[09:42:22] Warning: "" "" "" "" 147466080 147466208
[09:42:22] Warning: "" "" "" "" 147339080 147466176
[09:42:22] Warning: "" "" "" "" 147339080 147466208
[09:42:22] Warning: "" "" "" "" 147466256 147466176
[09:42:22] Warning: "" "" "" "" 147466256 147466208
[09:42:22] Warning: "" "" "" "" 147466256 147466176
[09:42:22] Warning: "" "" "" "" 147466256 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466720 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466176
[09:42:22] Warning: "" "" "" "" 147466464 147467472
[09:42:22] Warning: "" "" "" "" 147466464 147466208
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147339056
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147339056
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147339056
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147339056
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147339056
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147467464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 147466464 147466160
[09:42:22] Warning: "" "" "" "" 147466464 147468888
[09:42:22] Warning: "" "" "" "" 7143521 7208960
[09:42:22] Warning: "" "" "" "" 147466464 147465832
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
[09:42:22] Warning: "" "" "" "" 147466464 147468408
[09:42:22] Warning: "" "" "" "" 147466464 147468440
« Последнее редактирование: Февраль 25, 2013, 06:47 от lolbla2 » Записан
Vass
Гость
« Ответ #1 : Февраль 25, 2013, 08:08 »

Пустой конструктор копирования. Надо написать корректный.
Записан
GreatSnake
Джедай : наставник для всех
*******
Offline Offline

Сообщений: 2921



Просмотр профиля
« Ответ #2 : Февраль 25, 2013, 08:17 »

Пустой конструктор копирования. Надо написать корректный.
В данном случае удалить его вообще.
Записан

Qt 5.11/4.8.7 (X11/Win)
lolbla2
Гость
« Ответ #3 : Февраль 25, 2013, 08:32 »

Пустой конструктор копирования. Надо написать корректный.

Да вот это уже выяснил, а что в нём по умолчанию? Не объявить его вообще я не могу ибо Q_DECLARE_METATYPE  будет бузить что нет его.
Записан
GreatSnake
Джедай : наставник для всех
*******
Offline Offline

Сообщений: 2921



Просмотр профиля
« Ответ #4 : Февраль 25, 2013, 08:47 »

Код
C++ (Qt)
Q_DECLARE_METATYPE(Channel);
Q_DECLARE_METATYPE(QList<Channel>);
Ты засовываешь Channel и QList<Channel> в QVariant?
Записан

Qt 5.11/4.8.7 (X11/Win)
lolbla2
Гость
« Ответ #5 : Февраль 25, 2013, 09:14 »

Код
C++ (Qt)
Q_DECLARE_METATYPE(Channel);
Q_DECLARE_METATYPE(QList<Channel>);
Ты засовываешь Channel и QList<Channel> в QVariant?

Пока нет, но может и понадобится засунуть в вариант. А вообще нужно для того чтобы использовать в сигналах слотах свой тип, сигнал channelsReceived(QList<Channels>). Так-то сигналы и слоты работают, но плювался ворнингом QMetaProperty::read: Unable to handle unregistered datatype 'QList<Channel>' for property 'QDeclarativeBoundSignalParameters::channels'. Сейчас чот пропал этот ворнинг, хотя вроде ничего такого не делал, а наоборот убрал эти Q_DECLARE_METATYPE
Записан
Vass
Гость
« Ответ #6 : Февраль 25, 2013, 13:50 »

Да вот это уже выяснил, а что в нём по умолчанию? Не объявить его вообще я не могу ибо Q_DECLARE_METATYPE  будет бузить что нет его.

По умолчанию в нем поверхностное копирование всех полей, в конкретно вашем случае просто
приравняйте всем членам класса их же аналоги из объекта other
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.19 секунд. Запросов: 22.