PDA

View Full Version : [SOLVED]Weird compile error QObject, QVector



Alir3z4
30th January 2012, 14:48
Hi
I have a weird compile error which is related to QVector :|
here's the error


make: Entering directory `/home/alireza/dev/qt/yoDownet-build-desktop-Qt_in_PATH_Debug'
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I../yoDownet -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtSql -I/usr/include -I. -I. -I../yoDownet -I. -o fileinfo.o ../yoDownet/yoUtils/fileinfo.cpp
In file included from ../yoDownet/yoUtils/fileinfo.h:7:0,
from ../yoDownet/yoUtils/fileinfo.cpp:1:
/usr/include/QtCore/qobject.h: In copy constructor 'UriStatus::UriStatus(const UriStatus&)':
../yoDownet/yoUtils/uristatus.h:6:7: instantiated from 'void QVector<T>::realloc(int, int) [with T = UriStatus]'
/usr/include/QtCore/qvector.h:337:3: instantiated from 'void QVector<T>::detach_helper() [with T = UriStatus]'
/usr/include/QtCore/qvector.h:398:9: instantiated from 'QVector<T>& QVector<T>::operator=(const QVector<T>&) [with T = UriStatus]'
../yoDownet/yoUtils/fileinfo.cpp:30:13: instantiated from here
/usr/include/QtCore/qobject.h:333:5: error: 'QObject::QObject(const QObject&)' is private
../yoDownet/yoUtils/uristatus.h:6:7: error: within this context
In file included from /usr/include/QtCore/QVector:1:0,
from ../yoDownet/yoUtils/fileinfo.h:6,
from ../yoDownet/yoUtils/fileinfo.cpp:1:
/usr/include/QtCore/qvector.h: In member function 'void QVector<T>::realloc(int, int) [with T = UriStatus]':
/usr/include/QtCore/qvector.h:532:17: note: synthesized method 'UriStatus::UriStatus(const UriStatus&)' first required here
make: Leaving directory `/home/alireza/dev/qt/yoDownet-build-desktop-Qt_in_PATH_Debug'
make: *** [fileinfo.o] Error 1
18:44:36: The process "/usr/bin/make" exited with code 2.
Error while building project yoDownet (target: Desktop)
When executing build step 'Make'

class source

#ifndef FILEINFO_H
#define FILEINFO_H

#include <QObject>
#include <QString>
#include <QVector>
#include "uristatus.h"

class FileInfo : public QObject
{
Q_OBJECT
public:
explicit FileInfo(QObject *parent = 0);

void setIndex(const QString &index);
void setPath(const QString &path);
void setLength(const QString &length);
void setSelected(const QString &selected);
void setUris(const QVector<UriStatus> &uris);

QString index() const;
QString path() const;
QString length() const;
QString selected() const;
QVector<UriStatus> uris() const;

private:
QString _index;
QString _path;
QString _length;
QString _selected;
QVector<UriStatus> _uris;
};

#endif // FILEINFO_H


if you want the whole source code, it's on the git repo
http://sourceforge.net/p/yodownet/git/..../tree/ (http://sourceforge.net/p/yodownet/git/ci/b7cac562ff0200e0332c1402f6c954473c025e19/tree/)
or simply just clone it

git clone git://git.code.sf.net/p/yodownet/git yodownet-git

i really get confused by this error and i tried alot of ways, but when i comment declaration/definition of this

QVector<UriStatus> uris() const;
then the project will compiled successfully

thanks

Lykurg
30th January 2012, 15:45
You can't use QObject in QVector. You have to use pointers:
QVector<UriStatus*> uris() const;


...from the documentation
QVector's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, indexOf() and lastIndexOf() expect the value type to support operator==(). These requirements are documented on a per-function basis.

Alir3z4
30th January 2012, 16:07
Hmmmm,
Thank you
Your Quote from the qt documentation is the main point
diff (http://sourceforge.net/p/yodownet/git/ci/a3ab710da97b2a8bde210378f75e5dda7ed82c6d/)
Solved!