Results 1 to 3 of 3

Thread: currentIndex().internalPointer() problem

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default currentIndex().internalPointer() problem

    Hi,

    I have this code as part of my Dialog with a QListView and QGraphicsView:

    Qt Code:
    1. void TextureDialog::on_toolButtonAddLayer_clicked(){
    2. QString fileName = QFileDialog::getOpenFileName(this, tr("Abrir imagen"), workingDirectory,
    3. tr("Imagenes (*.png *.xpm *.jpg)"));
    4. if(fileName.isEmpty()) return;
    5. workingDirectory=QFileInfo(fileName).absolutePath();
    6.  
    7. GraphicsObjectItem *objectItem=objectPreviewScene->addLayer(fileName);
    8. StandardItem *item=new StandardItem(objectItem, QIcon(fileName), fileName);
    9. qDebug()<<"objectItem: "<<objectItem<<endl<<item->sceneItem();
    10. int row=listModelLayers->rowCount();
    11.  
    12. listModelLayers->appendRow(item);
    13. listViewLayers->setCurrentIndex(listModelLayers->index(row, 0));
    14. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TextureDialog::moveUp(){
    2. StandardItem *item;
    3.  
    4. item=static_cast<StandardItem*>(listViewLayers->currentIndex().internalPointer());
    5.  
    6. qDebug()<<item->sceneItem();
    7. //if(item){
    8. //qDebug()<<item;
    9. //}
    10. //qDebug()<<static_cast<QObject*>(item)->objectName();
    11. }
    To copy to clipboard, switch view to plain text mode 

    It executes in this order, and the debug exit is:

    Ejectuando...
    objectItem: QGraphicsItem(this = 0x81cfe78 , parent = 0x0 , pos = QPointF( 0 , 0 ) , z = 0 , flags = { "isVisible|isEnabled" })
    QGraphicsItem(this = 0x81cfe78 , parent = 0x0 , pos = QPointF( 0 , 0 ) , z = 0 , flags = { "isVisible|isEnabled" })
    QGraphicsItem(0)
    ---------------------- Finalizado normalmente ----------------------
    Someone can help me to fix this problem?

    Thanks

  2. #2
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: currentIndex().internalPointer() problem

    StandarItem class:

    Qt Code:
    1. class StandardItem:public QStandardItem{
    2. public:
    3. StandardItem(GraphicsObjectItem *item, QIcon icon=QIcon(), QString text=QString());
    4.  
    5. GraphicsObjectItem* sceneItem();
    6. private:
    7. GraphicsObjectItem *m_sceneItem;
    8. };
    9.  
    10. StandardItem::StandardItem(GraphicsObjectItem *item, QIcon icon, QString text):QStandardItem(icon, text){
    11. m_sceneItem=item;
    12. }
    13.  
    14. GraphicsObjectItem* StandardItem::sceneItem(){
    15. return m_sceneItem;
    16. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: currentIndex().internalPointer() problem

    I have solved it changing the moveUp() function to:

    Qt Code:
    1. void TextureDialog::moveUp(){
    2. StandardItem *item=static_cast<StandardItem*>(listModelLayers->itemFromIndex(listViewLayers->currentIndex()));
    3.  
    4. qDebug()<<item->text()<<endl<<item->sceneItem();
    5. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.