Results 1 to 2 of 2

Thread: How to use "Foreach" with "Qaxobject"?

  1. #1
    Join Date
    Apr 2016
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default How to use "Foreach" with "Qaxobject"?

    I want to pick subelements from a Qaxobject,but it is failed with Vs2015:
    Qt Code:
    1. QString x = "";
    2. QAxObject* MyFrames = MyWebObj->querySubObject("Document")->querySubObject("Frames");
    3.  
    4. foreach(QAxObject* MyFrame, MyFrames)//somethingwrong here....
    5. {
    6. x += MyFrame->querySubObject("Document")->querySubObject("All")
    7. ->querySubObject("Item(Int32)", 0)->dynamicCall("OuterHtml()").toString();
    8. }
    9. QAxObject* MyAll=MyWebObj->querySubObject("Document")->querySubObject("All")->querySubObject("Item(Int32)", 0);
    10. x= MyAll->dynamicCall("OuterHtml()").toString();//workable
    11. qDebug() << x;
    12. return x;
    To copy to clipboard, switch view to plain text mode 

    so I have to change it with for loop:
    Qt Code:
    1. QString x = "";
    2. QAxObject* MyFrames = MyWebObj->querySubObject("Document")->querySubObject("Frames");
    3.  
    4. QAxObject* MyFrame = 0;
    5. x = MyWebObj->querySubObject("Document")->querySubObject("All")
    6. ->querySubObject("Item(Int32)", 0)->dynamicCall("OuterHtml()").toString();
    7. for(int i=0;;i++)
    8. {
    9. MyFrame = MyFrames->querySubObject("Item(Int32)", i);
    10. if (!MyFrame) break;
    11. x += MyFrame->querySubObject("Document")->querySubObject("All")
    12. ->querySubObject("Item(Int32)", 0)->dynamicCall("OuterHtml()").toString();
    13. }
    14. qDebug() << x;
    15. return x;
    To copy to clipboard, switch view to plain text mode 

    My question is how to use foreach with Qaxobject, as it looks more simple.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use "Foreach" with "Qaxobject"?

    foreach, like the C++11 range-for, works on a container, i.e. an object of a class that provides STL-style iterators.

    QAxObject does not have those.

    You could use assignment-in-condition if you want to have something like
    Qt Code:
    1. for (int i = 0; (MyFrame = MyFrames->querySubObject("Item(Int32)", i)) != 0; ++i) {
    2. // ....
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 10:02
  2. QSqlError("", "Parameter count mismatch", "")
    By Alberto7 in forum Newbie
    Replies: 2
    Last Post: 9th October 2015, 22:09
  3. Replies: 3
    Last Post: 16th March 2015, 07:31
  4. Replies: 1
    Last Post: 3rd December 2013, 02:19
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Tags for this Thread

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.