Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: apparently impossible qobject_cast is working!?

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

    Default Re: apparently impossible qobject_cast is working!?

    Quote Originally Posted by FS Lover View Post
    for what reason do you think it is special?
    Because here you don't care that it is a proxy, you just want your original model index back. It's a shortcut over using the activated() signal that carries a string and finding that string in your model. So the same functionality could be obtained without qobject_cast with one or two additional lines of code.

    what difference does it make regarding such uses we need?
    This is not a need where you want to use the completionModel for anything. You just want the original model index back.

    you wanted an example case and I showed you one clear, simple, standard, and completely official one.
    No, you didn't.

    I think its clear enough to everyone.
    So file a bug report to Qt Software. They won't change the API because it would break compatibility with existing applications but they might say "you're right, it should have been a QAbstractProxyModel".

    so you have the responsibility to prove any further claim you make here.
    I don't have a reponsibility to prove anything. You should always use the most general interface to an object and that's a rule of a thumb in OO Software Engineering.

    base model may be any model that can be potentially complex, costly to process, harder to work with, etc.
    but regarding auto completion's suggestions and user's choice among them, many times we need only simple features without any further/external dependencies,
    so a simple and shortened model that contains only the relevant items is the best to work with. that is what completionModel gives to us (a simple list model).
    I take it that in your implementation of Qt the source of QCompleter::setModel() doesn't contain a line:
    Qt Code:
    1. d->proxy->setSourceModel(mode);
    To copy to clipboard, switch view to plain text mode 
    which sets the source model of the completion model to the model you pass to it. So sorry, but there is no "simple list model" here. You have all the drawbacks of your original model plus an additional layer that returns the currently used list model to the user. And still you shouldn't care what it does. To you this is just "some" model that can be completely unrelated to your base model, especially if you subclass QCompleter and reimplement setModel - there might not be any proxy there anymore.

    maybe I don't understand your meaning clearly.
    can you explain more?
    clearly, some feature of the example will not work without that functionality.
    Examples often use hacks or simplifications. This is one of them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    It's a shortcut over using the activated() signal that carries a string and finding that string in your model.
    `activated ' isn't equal with `highlighted' in functionality.
    QCompleter::highlighted:
    This signal is sent when an item in the popup() is highlighted by the user.
    QCompleter::activated:
    This signal is sent when an item in the popup() is activated by the user (by clicking or pressing return).
    So file a bug report to Qt Software. They won't change the API because it would break compatibility with existing applications but they might say "you're right, it should have been a QAbstractProxyModel".
    it is now a QAbstractProxyModel.
    first thing I questioned here was just "why is qobject_cast successful?"
    the answer is, because returned object is indeed a QAbstractProxyModel subclass.
    but it is not mentioned in the documentation.
    You should always use the most general interface to an object and that's a rule of a thumb in OO Software Engineering.
    apparently qt's own educational example does not follow that.
    so I think you can fill a bug report!!
    Last edited by FS Lover; 2nd June 2009 at 06:38.

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

    Default Re: apparently impossible qobject_cast is working!?

    Quote Originally Posted by FS Lover View Post
    `activated ' isn't equal with `highlighted' in functionality.
    QCompleter::highlighted:
    This signal is sent when an item in the popup() is highlighted by the user.
    QCompleter::activated:
    This signal is sent when an item in the popup() is activated by the user (by clicking or pressing return).
    Ok, then over "highlighter" carrying a string.

    but it is not mentioned in the documentation.
    Yes, along with many other things that are not mentioned there.

    apparently qt's own educational example does not follow that.
    ???

    Does it expose any API?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    good fight:

  5. #25
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    So the same functionality could be obtained without qobject_cast with one or two additional lines of code.
    can you please write those two additional lines for that example?
    please change the member function and insert the code here so that I can compile and examine it to understand the truth. I am not sure about anything, since I am a newbie anyway.
    I think if it's so easy and short you can spend a little time on it to go to the practice and take this debate closer to it's destination. we should try to make it more clear and get benefit from the time and energy we spent here. further the topic will be much more of use for others if we can make a definitive conclusion.
    personally I filled a bug report for the documentation (using non-standard method and undocumented API) and I sent the link of this topic for them too. but it's possible that they discard that bug report.
    Last edited by FS Lover; 3rd June 2009 at 07:11.

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

    Default Re: apparently impossible qobject_cast is working!?

    I just have to stop answering to all those flames... But what can I say, I do love them...

    Use QCompleter::currentCompletion() to find a path in the original model and then use QAbstractItemModel::match() to find the proper index in the model.

    A possible implementation:
    Qt Code:
    1. QStringList path = completer->currentCompletion().split(".");
    2. const QAbstractItemModel *model = treeView->model();
    3. QModelIndex sourceIndex;
    4. while(!path.isEmpty()){
    5. sourceIndex = model->match(model->index(0,0, sourceIndex), Qt::DisplayRole, path.first(), 1).first();
    6. path.removeFirst();
    7. }
    8. treeView->selectionModel()->select(sourceIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
    9. treeView->scrollTo(index);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #27
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    your code does not work properly.
    run the app, type 'p', scroll to 'Parent2'; 'Parent2' does not get selected and 'Parent1' remains selected.
    Last edited by FS Lover; 6th June 2009 at 08:29.

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

    Default Re: apparently impossible qobject_cast is working!?

    Quote Originally Posted by FS Lover View Post
    your code does not work properly.
    So improve it It's a proof of concept.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    this was my submitted bug report: [Issue N255532] using a non-standard method in an example

    <qt installation dir>/examples/tools/treemodelcompleter/mainwindow.cpp: highlight member function

    it uses completionModel's QAbstractProxyModel interface which is
    apparently non-standard and not documented in the class reference.
    why an educational example should make use of non-standard methods and
    undocumented interfaces?

    I received the answer recently:

    Basically, the implementation of QCompleter uses a QAbstractProxyModel
    subclass to wrap the model, and the writer of the example relied on this
    knowledge to write the highlight() function.

    Note that the return value of completionModel() is a QAbstractItemModel
    pointer purely for generality - it could have been a QAbstractProxyModel
    (this would have made things clearer).

    I doubt that anyone will change the implementation of this class now, so
    we'll go ahead and document the behavior.

    Regards,

    David
    --
    David Boddie
    Senior Technical Writer
    Nokia, Qt Software

  10. #30
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    additionally, it seems that your suggested method can never differentiate between nodes that have the same text for the completer
    and have the same parent too.
    and I think indeed no other method than using QAbstractProxyModel's interface can do the job well for all possible cases;
    using it is more general and simple.
    Last edited by FS Lover; 16th June 2009 at 07:41.

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

    Default Re: apparently impossible qobject_cast is working!?

    But still David agrees with what I said - it is the way it is to expose a more general interface.

    Quote Originally Posted by FS Lover View Post
    additionally, it seems that your suggested method can never differentiate between nodes that have the same text for the completer
    and have the same parent too.
    Read the docs of the completer class again. It requires nodes (siblings) to be unique.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    Read the docs of the completer class again. It requires nodes (siblings) to be unique.
    I didn't find such thing. can you show me?

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

    Default Re: apparently impossible qobject_cast is working!?

    Quoting completer docs:
    QCompleter can look for completions in tree models, assuming that any item (or sub-item or sub-sub-item) can be unambiguously represented as a string by specifying the path to the item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #34
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    so in qt's Tree Model Completer example or any app like that, if we had a source tree like this one:
    Qt Code:
    1. Parent1
    2. male
    3. fred 23
    4. male
    5. jim 18
    6. female
    7. sara 20
    To copy to clipboard, switch view to plain text mode 
    what method do you suggest for getting navigation via qcompleter working properly?
    I tested the example with the above tree (corresponding resource file is resources\treemodel.txt) ; it works with the QAbstractProxyModel method perfectly.

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

    Default Re: apparently impossible qobject_cast is working!?

    Just give me a break, please. Do whatever you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #36
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    ...
    ...
    ...

  17. #37
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: apparently impossible qobject_cast is working!?

    you can answer for example:
    - we shouldn't write such apps (say this to the programmer of the qt's official example too).
    - or, we shouldn't have such tree structures

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

    Default Re: apparently impossible qobject_cast is working!?

    Or we should use qobject_cast. Wait... we do use qobject_cast. So I guess this is fine. Glory for the open-source world.

    EOT
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.