Results 1 to 8 of 8

Thread: Qstandarditem throws error while setting a item

  1. #1
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Qstandarditem throws error while setting a item

    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*>(file Name));
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qstandarditem throws error while setting a item

    Qt Code:
    1. previewPane.push_back(QVector<QStandardItem*>(file Name));
    To copy to clipboard, switch view to plain text mode 
    What is that suppose to mean??
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Qstandarditem throws error while setting a item

    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
    /*******************************************/

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qstandarditem throws error while setting a item

    fileName contains the name of the file while looping through the directory
    Then QVector<QStandardItem*>() should take a QStandardItem* and not a QString!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Qstandarditem throws error while setting a item

    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*>(item 0));

    }
    /************************************************** ******/

    where item0 is of QStandardItem type, but still it throws error.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qstandarditem throws error while setting a item

    Post the REAL code please, in code tags.
    And what is the exact error you get?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Qstandarditem throws error while setting a item

    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*>(item 0));

    }

    }
    /**********************************************/

    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:isplayRole) 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;

    };
    /************************************************** **********/
    Last edited by kamlmish; 3rd December 2010 at 04:09.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qstandarditem throws error while setting a item

    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.

Similar Threads

  1. Replies: 1
    Last Post: 16th June 2010, 20:19
  2. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  3. py2app-deployed PyQt app -- throws QObject threading error
    By tory108 in forum Installation and Deployment
    Replies: 4
    Last Post: 20th January 2009, 20:16
  4. QStandardItem: Setting Top Column Data?
    By AaronMK in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2008, 20:13
  5. Setting an icon to an Item in a QlistWidget
    By LordQt in forum Qt Programming
    Replies: 18
    Last Post: 23rd August 2007, 22:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.