Passing parameters to slots
-
Ok thanks for the help!
-
ok so I changed the connect function to:
@connect(webView, SIGNAL(loadProgress(int)), SLOT(loadBar(int)));@
It compiles, but doesn't seem to be called whenever the webView is loading.
Im starting to think its trouble with the slot itself:@void browseTab::loadBar(int progress)
{
if(progress <= 25)
{
SearchBar->setStyleSheet(
"border-right:2px solid blue;"
);
}
if(progress == 50)
{
SearchBar->setStyleSheet(
"border-right:2px solid blue;"
"border-bottom:2px solid blue;"
);
}
if(progress == 75)
{
SearchBar->setStyleSheet(
"border-right:2px solid blue;"
"border-bottom:2px solid blue;"
"border-left:2px solid blue;"
);
}
if(progress == 100)
{
SearchBar->setStyleSheet(
"border-right:2px solid blue;"
"border-bottom:2px solid blue;"
"border-left:2px solid blue;"
"border-top:2px solid blue;"
);
}
if(progress == 101)
{
SearchBar->setStyleSheet(
"border-right:2px solid black;"
"border-bottom:2px solid black;"
"border-left:2px solid black;"
"border-top:2px solid black;"
);
}
}@Basically I'm using the searchBar as a progress bar by changing the color of the sides as the page loads. Obviously it is not working. Ideas?
-
To check if a slot is called, stick a qDebug() inside it.
Also, you check if progress equals a particular value. Your slot won't do anything if it receives 49 or 51. It's best not to assume that every value between 1 and 100 will be received.
-
yes int progress = 0. Should I change that? If not every value will be called, what should I do in the if() statements that are called when it reaches certain points? Is there a range of values I should call? if so, how do I do that?
-
You don't get to choose which values you receive -- QWebView is responsible for that.
Use qDebug() to print the value of progress each time your slot is called. That should help you decide what to do.
-
ok I removed the default value from int progress. There is still nothing happening
-
Use qDebug() to print progress. (Removing the default value should have no effect whatsoever)
-
where do I place qDebug()?
-
What debugging techniques are you familiar with? Have you used printf() before?
-
nope Ive never used printf() or qDebug() before
-
See "QDebug | Basic Use":http://qt-project.org/doc/qt-5/QDebug.html#basic-use for an example.
It is a very simple but very useful technique to check your program. If you put qDebug() in a function, it will print a message in your Application Output pane* every time that function is called. If the message doesn't appear, that means your function hasn't been called. once you play with it, I'm sure you can think of other uses for qDebug().
Use qDebug() to:
Check if loadBar() is called
Examine the value of progress inside loadBar()
*(If you don't know where the Application Output pane is, search the "Qt Creator | User Interface":http://qt-project.org/doc/qtcreator-3.0/creator-quick-tour.html#application-output page)