Results 1 to 20 of 24

Thread: qt4 QStringList with model/view

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default qt4 QStringList with model/view

    Qt Code:
    1. QStringList Destinataires::getDestList()
    2. {
    3. int rowCount = model->rowCount();
    4. int i;
    5.  
    6. QItemSelectionModel *sel = qDestin->selectionModel();
    7. for( i = 0; i < rowCount; i++ )
    8. if ( sel->isRowSelected( i, qDestin->rootIndex() ) )
    9. s = model->data( model->index( i, 0 ) ); <- compile error
    10. rows.push_back( s );
    11. return rows;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. 96 C:\Qt\test\sms\destin.cpp no match for 'operator=' in 's = *(((Destinataires*)this)->Destinataires::model->QAbstractItemModel::_vptr$QObject + 68u)(((const QModelIndex&)((const QModelIndex*)(&*(((Destinataires*)this)->Destinataires::model->QAbstractItemModel::_vptr$QObject + 48u)(i, 0, ((const QModelIndex&)((const QModelIndex*)(&QModelIndex()))))))), 0)'
    To copy to clipboard, switch view to plain text mode 

    What should I do to retrieve the QString s from the model ?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: qt4 QStringList with model/view

    Qt Code:
    1. QStringList Destinataires::getDestList()
    2. {
    3. QModelIndexList selected = selectionModel()->selectedIndexes();
    4. foreach (QModelIndex idx, selected)
    5. {
    6. // you only want strings in 1st column? the list of selection
    7. // indexes contain indexes for possible rest of colums also..
    8. if (idx.row() == 0)
    9. {
    10. rows << idx.data().toString();
    11. }
    12. }
    13. return rows;
    14. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt4 QStringList with model/view

    with
    Qt Code:
    1. QModelIndexList selected = selectionModel()->selectedIndexes();
    To copy to clipboard, switch view to plain text mode 

    I get compile error :
    89 C:\Qt\test\sms\destin.cpp `((Destinataires*)this)->Destinataires::selectionModel' cannot be used as a function

    Sorry I am completly a beginner in QT4 and model/views.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: qt4 QStringList with model/view

    Right, I missed the qDestin ptr.. How about this:
    Qt Code:
    1. QModelIndexList selected = qDestin->selectionModel()->selectedIndexes();
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to jpn for this useful post:

    incapacitant (15th March 2006)

  6. #5
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt4 QStringList with model/view

    Yes what you say works perfectly. QT4 is hard to understand for me.

  7. #6
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt4 QStringList with model/view

    As I want all rows your code has become :
    Qt Code:
    1. QStringList Destinataires::getDestList()
    2. {
    3. QStringList rows;
    4. QModelIndexList selected = qDestin->selectionModel()->selectedIndexes();
    5. foreach (QModelIndex idx, selected)
    6. rows << idx.data().toString();
    7.  
    8. return rows;
    9. }
    To copy to clipboard, switch view to plain text mode 


    But there you declare "QModelIndexList". What does it mean ?
    Related Non-Memberstypedef QModelIndexList
    Synonym for QList<QModelIndex>.
    Completly lost.

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: qt4 QStringList with model/view

    As docs say, it's just a synonym for a QList containing QModelIndexes.

    All view's have a selection model which keeps track of selected items.
    There might be multiple selected "items", so the selection cannot just be a single "item".
    So the view's selection model needs to return a list of selected indexes.

    QModelIndexList QItemSelectionModel::selectedIndexes () const

    Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.

  9. The following user says thank you to jpn for this useful post:

    incapacitant (15th March 2006)

  10. #8
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt4 QStringList with model/view

    There is a pre-defined type for all QList ?
    Here we have QList<QStrings>.
    Would it be still the same QModelIndexList ?
    with QList<Int>, or another type ?

  11. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: qt4 QStringList with model/view

    Quote Originally Posted by incapacitant
    There is a pre-defined type for all QList ?
    Here we have QList<QStrings>.
    Would it be still the same QModelIndexList ?
    with QList<Int>, or another type ?
    Actually, QStringList and QList<QString> are different. QStringList inherits QList<QString> and adds some functionality..

    Because QList is a template class, you can have a list of basically anything, as long as it is an assignable data type.

    There are a few type definitions: QVariantList, QObjectList, QModelIndexList..
    You can take them as a more convenient way of writing the type or something..

    There is an essential reason for these type definitions, and I think it has something to do with Qt's meta-object system, only registered meta types can be used in signal and slot connections..
    But that's a whole different world to discuss

  12. The following user says thank you to jpn for this useful post:

    incapacitant (15th March 2006)

  13. #10
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt4 QStringList with model/view

    Well now the next question is how do I retrieve the ith item number of a QStringList ?

    (i am lost with this)

  14. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: qt4 QStringList with model/view

    Take a look at the documentation and see what methods QList offers..

    You can use for example method at(int i) or operator [].
    Qt Code:
    1. QString row = rows.at(i);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QString row = rows[i];
    To copy to clipboard, switch view to plain text mode 

  15. The following user says thank you to jpn for this useful post:

    incapacitant (15th March 2006)

Similar Threads

  1. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  2. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  3. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  4. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 21: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.