Results 1 to 2 of 2

Thread: Qt progressBar getting Unhandled exception how detect when parent widget is done load

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default Qt progressBar getting Unhandled exception how detect when parent widget is done load

    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 :
    Qt Code:
    1. class MainWindowMainWindowContainer : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindowContainer(QWidget *parent = 0);
    7.  
    8. public slots:
    9.  
    10. void adjustLocation();
    11. void changeLocation();
    12. void adjustTitle();
    13. void setProgress(int p);
    14. void finishLoading(bool);
    15. void finishedSlot(QNetworkReply* reply);
    16.  
    17.  
    18. private:
    19. Ui::OnLineBack_mainWindow ui;
    20. int progress;
    21.  
    22. void createWebViewActions();
    23. void setprogressBar(int progress,bool show);
    24.  
    25. };
    26.  
    27. MainWindowContainer::MainWindowContainer(QWidget* parent) :
    28. QMainWindow(parent),
    29.  
    30. {
    31. ui.setupUi(this);
    32. progress = 0;
    33.  
    34.  
    35. createWebViewActions();
    36. ui.webView->load(QUrl("www.cnnnn.com"));
    37. ui.webView->show();
    38.  
    39. pb = new QProgressBar(statusBar());
    40. pb->setTextVisible(false);
    41. pb->hide();
    42. statusBar()->addPermanentWidget(pb);
    43. }
    44. void MainWindowContainer::createWebViewActions()
    45. {
    46. connect(ui.webView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
    47. connect(ui.webView, SIGNAL(titleChanged(QString)), SLOT(adjustTitle()));
    48. connect(ui.webView, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
    49. connect(ui.webView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
    50. connect(ui.webView, SIGNAL(linkClicked(const QUrl&)),this, SLOT(linkClicked(const QUrl&)));
    51.  
    52. }
    53. void MainWindowContainer::setProgress(int p)
    54. {
    55. progress = p;
    56. adjustTitle();
    57. }
    58. void MainWindowContainer::adjustTitle()
    59. {
    60. qApp->processEvents();
    61.  
    62. pb->show();
    63. if (progress <= 0 || progress >= 100)
    64. {
    65. QString titl = ui.webView->title();
    66. statusBar()->showMessage(titl);
    67. setprogressBar(-1,false);
    68.  
    69. }
    70. else
    71. {
    72.  
    73. statusBar()->showMessage(QString("%1 (%2%)").arg(ui.webView->title()).arg(progress));
    74. setprogressBar(progress,true);
    75. }
    76. }
    77.  
    78. void MainWindowContainer::finishLoading(bool)
    79. {
    80. progress = 100;
    81. adjustTitle();
    82.  
    83. }
    84. void MainWindowContainer::setprogressBar(int progress,bool show)
    85. {
    86. if(show)
    87. {
    88. pb->show();
    89. pb->setRange(0,100);
    90. pb->setValue(progress);
    91. }
    92. else
    93. {
    94. pb->hide();
    95. }
    96. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt progressBar getting Unhandled exception how detect when parent widget is done

    Try this:
    Qt Code:
    1. MainWindowContainer::MainWindowContainer(QWidget* parent) :
    2. QMainWindow(parent),
    3.  
    4. {
    5. ui.setupUi(this);
    6. pb = new QProgressBar(statusBar());
    7. progress = 0;
    8.  
    9.  
    10. createWebViewActions();
    11. ui.webView->load(QUrl("www.cnnnn.com"));
    12. ui.webView->show();
    13.  
    14.  
    15. pb->setTextVisible(false);
    16. pb->hide();
    17. statusBar()->addPermanentWidget(pb);
    18. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Unhandled Exception from DLL QT 4.6.0
    By qlarity_three in forum Newbie
    Replies: 2
    Last Post: 5th February 2010, 20:11
  3. Unhandled Exception
    By dougbroadwell in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2009, 23:32
  4. Unhandled Exception in QTableView->setModel(QSqlTableModel)
    By dougbroadwell in forum Qt Programming
    Replies: 0
    Last Post: 19th March 2009, 20:35
  5. Unhandled Exception Err
    By Masih in forum Newbie
    Replies: 9
    Last Post: 25th July 2007, 21:28

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.