View Full Version : Qstandarditem throws error while setting a item
kamlmish
2nd December 2010, 11:41
Hi All
I have declared a vector as follows
QVector<QVector<QStandardItem*> > previewPane;
and then I am using the following code to set it to item
QDir dir("/home/kamlesh/Gall/GALL/images");
dir.setFilter(QDir::Files);
imgfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i = 0;i<imgfiles.size();i++)
{
fileName = imgfiles.at(i);
previewPane.push_back(QVector<QStandardItem*>(fileName));
}
high_flyer
2nd December 2010, 12:15
previewPane.push_back(QVector<QStandardItem*>(file Name));
What is that suppose to mean??
kamlmish
2nd December 2010, 12:25
fileName contains the name of the file while looping through the directory
previewPane.push_back(QVector<QStandardItem*>(file Name)) is used to append the QVector with fileName as item
My main aim is to create a array as below
/******************************************/
image1 image2
image3 image4
image5 image6
/*******************************************/
high_flyer
2nd December 2010, 12:35
fileName contains the name of the file while looping through the directory
Then QVector<QStandardItem*>() should take a QStandardItem* and not a QString!
kamlmish
2nd December 2010, 12:44
The actual code is below
/************************************************** ******/
QDir dir("/home/kamlesh/Gall/GALL/images");
dir.setFilter(QDir::Files);
imgfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i = 0;i<imgfiles.size();i++)
{
qDebug()<<" LOOP";
fileName = imgfiles.at(i);
item0 = new QStandardItem(fileName);
previewPane.push_back(QVector<QStandardItem*>(item0));
}
/************************************************** ******/
where item0 is of QStandardItem type, but still it throws error.
high_flyer
2nd December 2010, 13:56
Post the REAL code please, in code tags.
And what is the exact error you get?
kamlmish
3rd December 2010, 04:23
ERROR:
../GALL/displayframe.cpp:190:1: warning: "/*" within comment
../GALL/displayframe.cpp:231:3: warning: "/*" within comment
../GALL/displayframe.cpp:246:4: warning: "/*" within comment
../GALL/displayframe.cpp:275:4: warning: "/*" within comment
../GALL/displayframe.cpp:48: warning: unused parameter ‘parent’
../GALL/displayframe.cpp: In member function ‘void FrameDisplay::setItem()’:
../GALL/displayframe.cpp:64: error: invalid conversion from ‘QStandardItem*’ to ‘int’
../GALL/displayframe.cpp:64: error: initializing argument 1 of ‘QVector<T>::QVector(int) [with T = QStandardItem*]’
make: Leaving directory `/home/kamlesh/Gall/GALL-build-desktop'
make: *** [displayframe.o] Error 1
FUNCTION AND THE LINE WHERE I GET THE ERROR
/*******************************************/
void FrameDisplay::setItem()
{
QDir dir("/home/kamlesh/Gall/GALL/images");
dir.setFilter(QDir::Files);
imgfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i = 0;i<imgfiles.size();i++)
{
qDebug()<<" LOOP";
fileName = imgfiles.at(i);
item0 = new QStandardItem(fileName);
previewPane.push_back(QVector<QStandardItem*>(item0));
}
}
/**********************************************/
Header file
/************************************************/
#include <QAbstractTableModel>
#include <QtGui>
class FrameDisplay: public QStandardItemModel
{
Q_OBJECT
public:
FrameDisplay(QObject* parent = 0);
~FrameDisplay();
public:
int columnCount(const QModelIndex &) const;
int rowCount(const QModelIndex &) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool hasChildren ( const QModelIndex & parent = QModelIndex() ) ;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
void setItem();
public:
QLabel label ;
QStringList imgfiles;
QString fileName;
int row;
int col;
QStandardItem* item0;
QVector<QVector<QStandardItem*> > previewPane;
};
/************************************************** **********/
ChrisW67
3rd December 2010, 06:02
When people ask to see the real code in [code] tags it is usually for a reason. The highlighted line in the "FUNCTION AND THE LINE WHERE I GET THE ERROR" and your earlier post contains an obvious typo. As provided, the code will not compile but will generate a different message to the one you have given us.
The error message is telling you that your attempt to create a QVector<QStandardItem*> with a QStandardItem* is failing because there is no constructor matching that signature. Attempting to coerce your arguments to match one of the constructor options ultimately fails with this error.
I assume you are going to put these items into a QStandardItemModel anyway. Why not save yourself a bunch of obvious confusion about QVector<> and just put the items into the model from the start.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.