PDA

View Full Version : Qt progressBar getting Unhandled exception how detect when parent widget is done load



umen
30th March 2011, 13:08
im using Qt QProgressBar and place it in the statusBar on my main window Like this in the constructor .
then im running procsses (web page loadding in this case ) and trying to show the progress with .
But im getting Unhandled exception when it comes to pb->show() I guess it has to do something with loading the parent main windows and then the progress bar I was reading about the QAbstractEventDispatcher and processEvents but not understood how to implement it .

i did small test and put the pb->show() function call in button click signal/slut that means im triggering the pb->show() after the web page and the mainwindows fully loaded and its working fine without the exception. that make me belive there is problem with the event processing.

here is the class :

class MainWindowMainWindowContainer : public QMainWindow
{
Q_OBJECT

public:
MainWindowContainer(QWidget *parent = 0);

public slots:

void adjustLocation();
void changeLocation();
void adjustTitle();
void setProgress(int p);
void finishLoading(bool);
void finishedSlot(QNetworkReply* reply);


private:
Ui::OnLineBack_mainWindow ui;
int progress;

void createWebViewActions();
QProgressBar *pb;
void setprogressBar(int progress,bool show);

};

MainWindowContainer::MainWindowContainer(QWidget* parent) :
QMainWindow(parent),

{
ui.setupUi(this);
progress = 0;


createWebViewActions();
ui.webView->load(QUrl("www.cnnnn.com"));
ui.webView->show();

pb = new QProgressBar(statusBar());
pb->setTextVisible(false);
pb->hide();
statusBar()->addPermanentWidget(pb);
}
void MainWindowContainer::createWebViewActions()
{
connect(ui.webView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
connect(ui.webView, SIGNAL(titleChanged(QString)), SLOT(adjustTitle()));
connect(ui.webView, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
connect(ui.webView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
connect(ui.webView, SIGNAL(linkClicked(const QUrl&)),this, SLOT(linkClicked(const QUrl&)));

}
void MainWindowContainer::setProgress(int p)
{
progress = p;
adjustTitle();
}
void MainWindowContainer::adjustTitle()
{
qApp->processEvents();

pb->show();
if (progress <= 0 || progress >= 100)
{
QString titl = ui.webView->title();
statusBar()->showMessage(titl);
setprogressBar(-1,false);

}
else
{

statusBar()->showMessage(QString("%1 (%2%)").arg(ui.webView->title()).arg(progress));
setprogressBar(progress,true);
}
}

void MainWindowContainer::finishLoading(bool)
{
progress = 100;
adjustTitle();

}
void MainWindowContainer::setprogressBar(int progress,bool show)
{
if(show)
{
pb->show();
pb->setRange(0,100);
pb->setValue(progress);
}
else
{
pb->hide();
}
}

high_flyer
30th March 2011, 15:29
Try this:


MainWindowContainer::MainWindowContainer(QWidget* parent) :
QMainWindow(parent),

{
ui.setupUi(this);
pb = new QProgressBar(statusBar());
progress = 0;


createWebViewActions();
ui.webView->load(QUrl("www.cnnnn.com"));
ui.webView->show();


pb->setTextVisible(false);
pb->hide();
statusBar()->addPermanentWidget(pb);
}