Results 1 to 3 of 3

Thread: Problem with QSharedPointer

  1. #1
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Problem with QSharedPointer

    I have this code fragment

    Qt Code:
    1. QSharedPointer<QSqlTableModel> wrkTable; // defined in .h file
    2.  
    3.  
    4. wrkTable = dbgmgr.OpenDB("moz_downloads","","downloads.sqlite");
    5.  
    6. if (wrkTable)
    7. {
    8. ui->tableView->setModel(wrkTable); // error here
    9. ui->tableView->show();
    10. QItemSelectionModel *sm = ui->tableView->selectionModel();
    11. connect(sm, SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
    12. this, SLOT(rowMoved(QModelIndex, QModelIndex)));
    13.  
    14. dbgmgr.DebugInfo(true);
    15. }
    16. else
    17. qDebug() << "Error: " << dbgmgr.error;
    18. }
    To copy to clipboard, switch view to plain text mode 

    but in the line: ui->tableView->setModel(wrkTable);

    I get this error:
    Qt Code:
    1. /home/ocean/Development/Qt-Projects/SQLiteTest/mainwindow.cpp:30: error: no matching function for call to ‘QTableView::setModel(QSharedPointer<QSqlTableModel>&)
    2. /opt/qtsdk-2010.02/qt/include/QtGui/qtableview.h:71: note: candidates are: virtual void QTableView::setModel(QAbstractItemModel*)
    To copy to clipboard, switch view to plain text mode 
    I thought that if I change it to: ui->tableView->setModel(wrkTable.toWeakPointer());
    that it would resolve this problem, but it didn't.

    Seems like I spend more time fighting with pointers than writing code.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QSharedPointer


  3. #3
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt4 Qt/Embedded

    Default Re: Problem with QSharedPointer

    Thanks; that worked! I did not see that one.

Similar Threads

  1. QSharedPointer - how to prevent delete?
    By Piskvorkar in forum Qt Programming
    Replies: 7
    Last Post: 31st March 2010, 15:46
  2. QSharedPointer vs Boost::tr1::shared_ptr()
    By photo_tom in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 16:48
  3. Replies: 3
    Last Post: 7th August 2009, 13:05

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.