Results 1 to 2 of 2

Thread: QDirModel's index overloaded function

  1. #1
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QDirModel's index overloaded function

    Hi

    There is an issue with QDirModel that has been puzzling me for quite some time. There is a public function in this class with the following signature:
    Qt Code:
    1. QModelIndex index(const QString &path, int column = 0) const;
    To copy to clipboard, switch view to plain text mode 

    I have another class that inherits QDirModel:

    Qt Code:
    1. class MyDirModel : public QDirModel {
    2. }
    To copy to clipboard, switch view to plain text mode 

    now when I do something like in this:

    Qt Code:
    1. MyDirModel model;
    2. QModelIndex index = model.index(QString("/Users/anton"), 0);
    To copy to clipboard, switch view to plain text mode 

    it would give compilation error:

    Qt Code:
    1. no matching function for call to 'MyDirModel::index(QString, int)'
    To copy to clipboard, switch view to plain text mode 

    To workaround this I usually do something like this:

    Qt Code:
    1. MyDirModel *model;
    2. qobject_cast<QDirModel *>(model)->index(QString('..."), 0);
    To copy to clipboard, switch view to plain text mode 

    What's the trick here?

    I'm on Qt 4.6 under Mac. Not sure if it's reproducible on Windows

    Thanks
    Anton

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDirModel's index overloaded function

    Does your sub-class re-implement the other QDirModel::index (the one that takes int row, int column, const QModelIndex& parent), or declare some other member function named “index”?

    If so, that declaration hides all inherited functions by the same name. In that case, you could add:
    Qt Code:
    1. using QDirModel::index;
    To copy to clipboard, switch view to plain text mode 
    to the definition of your derived class to allow overload resolution of the name “index” to include member functions from QDirModel.

  3. The following user says thank you to Coises for this useful post:

    psih128 (27th January 2010)

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.