Re: Geometry of QWebElement
I would assume the page didn't have time to layout itself yet so height of the element was not calculated yet. I would wait for the QWebFrame::initialLayoutCompleted() signal before checking geometry.
Re: Geometry of QWebElement
Thank you for the quick reply!
Alright so I added a QEventloop to make sure that it reaches initialLayoutCompleted(). I'm still new to siganls and slots but I believe this is right. It does print something now! :D However it doesn't make any sense. Its some random characters, but it should return an int. Also "int height" instead of "QString height" always returns a 0. Any suggestions?
Code:
Opage = new QWebPage(this);
Opage->mainFrame()->setHtml(reply->readAll());
QWebElement doc = Opage->mainFrame()->documentElement();
connect(Opage->mainFrame(),SIGNAL(initialLayoutCompleted()),&loop, SLOT(quit()));
loop.exec();
QWebElementCollection elements = doc.findAll("div");
foreach (QWebElement element, elements)
{
QString height
= element.
geometry().
height();
qDebug() << height;
}
Output:
Code:
"?"
"?"
""?"
"""""r"
""A"
"("
"""*"
""*"
""j"
""""?"
"U"
""
"`"
""
""
""P"
"?"
"?"
"<"
"""""i"
Re: Geometry of QWebElement
QWebElement::geometry() returns a QRect, its height() method returns an int, so this line
Code:
QString height
= element.
geometry().
height();
is clearly wrong.
If you want a numerical value in a string use a formatting function, e.g. QString::number(), but why do you want a size value as a string?
Cheers,
_
Re: Geometry of QWebElement
Quote:
Originally Posted by
anda_skoa
QWebElement::geometry() returns a QRect, its height() method returns an int, so this line
Code:
QString height
= element.
geometry().
height();
is clearly wrong.
If you want a numerical value in a string use a formatting function, e.g. QString::number(), but why do you want a size value as a string?
Cheers,
_
Yep that did it! I feel a bit stupid now lol, I'm not sure what I was thinking :/
Thank you anda_skoa and wysota for your help!