Hi,
first of all sorry if I report in a new thread a question made in this discussion but the problem not seems strictly related to that particular case. The problems shows when I don't click any button in QMessageBox asking if install (in the sample code a simple QFile::copy()) a downloaded file: in this case pops up the same dialog because is emitted a new QHTTP::requestFinished() signal. If then I click ok/cancel on these QMessageBoxes I got segmentation fault and/or

ASSERT: "!isEmpty()" in file ../../include/QtCore/../../src/corelib/tools/qlist.h, line 248
If I click on the confirmation massage without pausing or remove the qmessagebox and install just after downloading no errors are reported.

Test yourself this code (sorry if no so minimal):

Qt Code:
  1. #include <QApplication>
  2. #include <QDialog>
  3. #include <QtGui>
  4. #include <QtNetwork>
  5.  
  6. #include <iostream>
  7.  
  8. class Dialog: public QDialog
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. Dialog(QWidget *parent = 0);
  14.  
  15. private slots:
  16. void httpRequestFinished(int requestId, bool error);
  17. void updateDataReadProgress(int bytesRead, int totalBytes);
  18. void readResponseHeader(const QHttpResponseHeader &responseHeader);
  19. void cancelDownload();
  20. void downloadFile();
  21.  
  22. private:
  23. QString fileName;
  24. QFile *file;
  25. QPushButton *downloadButton;
  26. QPushButton *closeButton;
  27. QProgressDialog *progressDialog;
  28. QHttp *http;
  29. int httpGetId;
  30. QDir dir;
  31. bool httpRequestAborted;
  32. void installFile();
  33. };
  34.  
  35. Dialog::Dialog(QWidget *parent)
  36. : QDialog(parent)
  37. {
  38. downloadButton = new QPushButton("Download");
  39. closeButton = new QPushButton("Close");
  40.  
  41. QHBoxLayout *buttonsLayout = new QHBoxLayout;
  42. buttonsLayout->addStretch();
  43. buttonsLayout->addWidget(downloadButton);
  44. buttonsLayout->addWidget(closeButton);
  45. buttonsLayout->addStretch();
  46.  
  47. setLayout(buttonsLayout);
  48.  
  49. connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
  50. connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
  51.  
  52. progressDialog = new QProgressDialog(this);
  53. http = new QHttp(this);
  54.  
  55. connect(http, SIGNAL(requestFinished(int, bool)),
  56. this, SLOT(httpRequestFinished(int, bool)));
  57. connect(http, SIGNAL(dataReadProgress(int, int)),
  58. this, SLOT(updateDataReadProgress(int, int)));
  59. connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
  60. this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
  61. connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
  62. }
  63.  
  64. void Dialog::downloadFile()
  65. {
  66. QUrl url("http://www.nih.at/libzip/index.html");
  67. QFileInfo fileInfo(url.path());
  68. QString fileName;
  69. fileName = QDir::tempPath() + fileInfo.fileName();
  70.  
  71. if (QFile::exists(fileName)) {
  72. if (QMessageBox::question(this,
  73. tr("HTTP"),
  74. trUtf8("There already exists a file called %1 in the current directory. Overwrite?")
  75. .arg(fileName),
  76. QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel)
  77. == QMessageBox::Cancel)
  78. return;
  79. QFile::remove(fileName);
  80. }
  81. file = new QFile(fileName);
  82. if (!file->open(QIODevice::WriteOnly)) {
  83. QMessageBox::information(this,
  84. tr("HTTP"),
  85. trUtf8("Impossibile salvare il file %1: %2.")
  86. .arg(fileName).arg(file->errorString()));
  87. delete file;
  88. file = 0;
  89. return;
  90. }
  91. QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
  92. http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
  93.  
  94. httpRequestAborted = false;
  95. httpGetId = http->get(url.path(), file);
  96.  
  97. progressDialog->setWindowTitle(tr("HTTP"));
  98. progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
  99. downloadButton->setEnabled(false);
  100. }
  101.  
  102. void Dialog::cancelDownload()
  103. {
  104. httpRequestAborted = true;
  105. http->abort();
  106. downloadButton->setEnabled(true);
  107. }
  108.  
  109. void Dialog::httpRequestFinished(int requestId, bool error)
  110. {
  111. std::cout << "httpRequestFinished()" << std::endl;
  112. if (requestId != httpGetId)
  113. return;
  114. if (httpRequestAborted) {
  115. if (file) {
  116. file->close();
  117. file->remove();
  118. delete file;
  119. file = 0;
  120. }
  121.  
  122. progressDialog->hide();
  123. return;
  124. }
  125.  
  126. if (requestId != httpGetId)
  127. return;
  128.  
  129. progressDialog->hide();
  130. file->close();
  131.  
  132. if (error) {
  133. file->remove();
  134. QMessageBox::information(this,
  135. tr("HTTP"),
  136. trUtf8("Download failed: %1.")
  137. .arg(http->errorString()));
  138. } else
  139. installFile();
  140.  
  141. delete file;
  142. file = 0;
  143. }
  144.  
  145. void Dialog::readResponseHeader(const QHttpResponseHeader &responseHeader)
  146. {
  147. if (responseHeader.statusCode() != 200) {
  148. QMessageBox::information(this,
  149. tr("HTTP"),
  150. trUtf8("Download failed: %1.").
  151. arg(responseHeader.reasonPhrase()));
  152. httpRequestAborted = true;
  153. progressDialog->hide();
  154. http->abort();
  155. return;
  156. }
  157. }
  158.  
  159. void Dialog::updateDataReadProgress(int bytesRead, int totalBytes)
  160. {
  161. if (httpRequestAborted)
  162. return;
  163.  
  164. progressDialog->setMaximum(totalBytes);
  165. progressDialog->setValue(bytesRead);
  166. }
  167.  
  168. void Dialog::installFile()
  169. {
  170. if (QMessageBox::question(this,
  171. tr("Ready"),
  172. trUtf8("If you don't click me quickly\nI will make some unwanted thing."),
  173. QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel)
  174. == QMessageBox::Ok) {
  175. QString fileName;
  176. QFileInfo fi(file->fileName());
  177. fileName = fi.fileName();
  178. file->copy(QDir::tempPath() + "copied-index.html");
  179. }
  180. downloadButton->setEnabled(true);
  181. }
  182.  
  183. int main(int argc, char *argv[])
  184. {
  185. QApplication app(argc,argv);
  186. Dialog *dialog = new Dialog;
  187. dialog->show();
  188. return app.exec();
  189. }
  190.  
  191. #include "main.moc"
To copy to clipboard, switch view to plain text mode