Results 1 to 4 of 4

Thread: QProgressDialog cancel signal is emitted always

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QProgressDialog cancel signal is emitted always

    Hello!

    I add a QProgressDialog in my project that shows a charge-and-calculate progress. After the process is complete, the QProgressDialog is supposed to be closed and deleted. But there is the possibility that the user might want to cancel the process, so I connected a slot to QProgressDialog's cancel() signal, so whenever the cancel() signal is emmited while clicking in QProgressDialog's Cancel button, the QProgressDialog is closed and deleted, and when its not, it is closed and deleted normally after the charge-and-calculate process is complete.

    Doing so, I found that the cancel() signal is beeing emitted by QProgressDialog even when the Cancel button is NOT triggered, that is, when the user allows the progress normally to its end. SO what happens is that my software crashes, since it tries to do a close() and delete in the normal code while the erroneos cancel slot had already done that before due to this erroneos cancel emited signal.

    Could this be a bug in Qt?

    Personally I see no problem in my code, it's quite simple:

    Qt Code:
    1. progressBarCarregaAtivos = new QProgressDialog(this);
    2. progressBarCarregaAtivos->setWindowTitle("Loading...");
    3. progressBarCarregaAtivos->setMinimum(0);
    4. progressBarCarregaAtivos->setMaximum(filesNames.size());
    5. progressBarCarregaAtivos->setLabelText("Loading shares data...");
    6. progressBarCarregaAtivos->setWindowModality(Qt::ApplicationModal);
    7. connect(progressBarCarregaAtivos,SIGNAL(canceled()),this,SLOT(slotProgressBarCanceled()));
    8. progressBarCarregaAtivos->show();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::slotProgressBarCanceled() //being called even when Cancel is not triggered
    2. {
    3. /*!
    4.   \brief chamado caso se aperte em "cancelar" quando esta sendo feito
    5.   o download em modo local. */
    6. qDebug() << "Cancelou carregamento de ativos";
    7.  
    8. timerCarregaVarios->stop();
    9. progressBarCarregaAtivos->close();
    10.  
    11. SAFEDELETE(timerCarregaVarios);
    12. SAFEDELETE(progressBarCarregaAtivos);
    13.  
    14. counter_carregaVarios = 0;
    15. carregaAtivosMux = 0;
    16.  
    17. filesNames.clear();
    18. vetor_ativos.clear();
    19.  
    20. Flags.start_automation = false;
    21. ui->actionStop_automation->setDisabled(false);
    22. ui->actionAnalyse_a_share->setDisabled(false);
    23. ui->actionReviewWindow->setDisabled(false);
    24. ui->actionAlarms->setDisabled(false);
    25.  
    26. slotMemoLog("Carregamento local cancelado.","","\n");
    27. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //Normal end code
    2. timerCarregaVarios->stop();
    3. SAFEDELETE(timerCarregaVarios); //???
    4.  
    5. disconnect(progressBarCarregaAtivos,SIGNAL(canceled()));
    6. progressBarCarregaAtivos->close();
    7. SAFEDELETE(progressBarCarregaAtivos)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QProgressDialog cancel signal is emitted always

    What is SAFEDELETE?

    Anyway deleting the sending object in a slot is not safe, so instead use deleteLater()
    Qt Code:
    1. progressBarCarregaAtivos->deleteLater();
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QProgressDialog cancel signal is emitted always

    Make a "proof of concept" project containing nothing except a plain, old, QDialog with a button that posts another QDialog. Connect slots to the OK and cancel signals and prove to yourself that there is no bug in Qt.

    If this works as you would expect it to, then start looking for the bug in your own code which causes the unexpected behavior. If it doesn't work, then post that code here for review.

    You should be able to do this in less than 20 lines of code.

    (My hunch: It looks like you have a timer in your code. I would bet that the error lies in the handling of the timeout signals).

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProgressDialog cancel signal is emitted always

    Quote Originally Posted by Santosh Reddy View Post
    What is SAFEDELETE?

    Anyway deleting the sending object in a slot is not safe, so instead use deleteLater()
    Qt Code:
    1. progressBarCarregaAtivos->deleteLater();
    To copy to clipboard, switch view to plain text mode 
    Hello Santosh,

    I tried deleteLater, same problem. In fact, first I thought that SAFEDELETE was doing the problem, but after the change I noticed that it could be something else, an than I found the wrong cancel signal being emitted.

    Qt Code:
    1. #define SAFEDELETE(_P) if(_P) {delete _P; _P = NULL;}
    To copy to clipboard, switch view to plain text mode 

    d_stranz, OK I'll see about it, but as I tried to say, no way I call cancel() for the QProgressDialog at least not if Ctrl+Shift+F is working properly!

    Edit: noticed that "progressBarCarregaAtivos->close();" in the second code part I show? Well, I discovered that if I comment that close(), the signal cancel() is not wrongly emitted. And I also discovered that it's not necessary to call that close() because the QProgressDialog is closed even without any call to it's close(). I guess it's because of the autoReset/autoClose issue.
    Last edited by Momergil; 31st January 2013 at 02:32.

Similar Threads

  1. Hide/show the Cancel button in a QProgressDialog
    By Vankata in forum Qt Programming
    Replies: 9
    Last Post: 24th February 2011, 20:43
  2. signal emitted when I zoom
    By mastupristi in forum Qwt
    Replies: 1
    Last Post: 8th July 2009, 17:02
  3. Signal emitted more than once?
    By dbrmik in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 12:44
  4. Program crash when a signal is emitted
    By croscato in forum Qt Programming
    Replies: 7
    Last Post: 22nd November 2008, 22:24
  5. How to show QProgressDialog without cancel button
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2007, 09:53

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.