Results 1 to 17 of 17

Thread: QUrlOperator doesn't emit finished signal

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QUrlOperator doesn't emit finished signal

    I want to get a php page via QUrlOperator, but url should be entered by end users. So url may belong to unreachable host. QT Docs states that QUrlOperator always - whether operation succeeds or fails - emits a finished signal. But amazingly i don't get always. Actually after a while i don't get anymore.
    More info to repliers:
    1- qInitNetwork... function is in the main so it's called.
    2- I get finished signals at least once.

    i'll also give you some source code to test it or find what's wrong with it.
    the program works as; one widget (which is mainwidget of application) opens another widget with a timeout continuously, then the opened widget tries to reach a url which is unreachable. When it gets finished signal it closes itself.

    So it works for five or more times, but after an unknown times of timer timeout program does not get finished signals.

    Notes:
    FileReader_ and MainUI_ are subclasses of QWidget it doesn't have any other subwidgets or operations.

    Qt Code:
    1. // header which uses qurloperator
    2. #ifndef FILEREADER_H
    3. #define FILEREADER_H
    4.  
    5. #include "FileReader_.h"
    6.  
    7. class QUrlOperator;
    8. class QNetworkOperation;
    9.  
    10. class FileReader : public FileReader_
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. FileReader(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    16. ~FileReader();
    17.  
    18. public slots:
    19. void stateChangedSlot(int state,const QString&);
    20. void finishedSlot(QNetworkOperation *operation);
    21.  
    22. private:
    23. QUrlOperator* m_op;
    24. };
    25.  
    26. #endif
    27.  
    28. // qurloperator using class's imp.
    29. #include <qurloperator.h>
    30. #include <qnetwork.h>
    31.  
    32. #include <iostream>
    33.  
    34. #include "filereader.h"
    35.  
    36. using namespace std;
    37.  
    38. FileReader::FileReader(QWidget* parent, const char* name, WFlags fl)
    39. : FileReader_(parent,name,fl)
    40. {
    41. // host part of url, which is here asdfasdf, should be unreachable. So host should not exist on network
    42. m_op = new QUrlOperator("http://asdfasdf/asdf/abcd.php");
    43.  
    44. connect(m_op, SIGNAL(connectionStateChanged(int,const QString&)), SLOT(stateChangedSlot(int,const QString&)));
    45. connect( m_op, SIGNAL(finished(QNetworkOperation*)), SLOT(finishedSlot(QNetworkOperation*)));
    46.  
    47. m_op->get();
    48. }
    49.  
    50. void FileReader::stateChangedSlot(int state,const QString& data)
    51. {
    52. cout << "conn state changed to: " << data.ascii() << endl;
    53.  
    54. switch( state ){
    55. case QNetworkProtocol::ConConnected:
    56. cout << "CONNECTED" << endl;
    57. break;
    58. case QNetworkProtocol::ConClosed:
    59. cout << "CONNECTION CLOSED" << endl;
    60. break;
    61. }
    62. }
    63.  
    64. void FileReader::finishedSlot(QNetworkOperation *operation)
    65. {
    66. switch( operation->operation() ){
    67. case QNetworkProtocol::OpGet:
    68. if ( operation->state() == QNetworkProtocol::StFailed ) {
    69. cerr << "finished but there is an error..." << endl;
    70. }
    71. else if ( operation->state() == QNetworkProtocol::StDone ) {
    72. cout << "connection successfully finished..." << endl;
    73. }
    74. }
    75.  
    76. close(true);
    77. }
    78.  
    79. FileReader::~FileReader()
    80. {
    81. delete m_op;
    82. }
    83.  
    84. // header of opening widget
    85. #ifndef MAINUI_H
    86. #define MAINUI_H
    87.  
    88. #include "MainUI_.h"
    89.  
    90. class QTimer;
    91. class FileReader;
    92.  
    93. class MainUI : public Form1
    94. {
    95. Q_OBJECT
    96.  
    97. public:
    98. MainUI(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    99.  
    100. public slots:
    101. void refreshInfo();
    102.  
    103. protected:
    104. QTimer* m_timer;
    105. FileReader* fileReader;
    106. };
    107.  
    108. #endif
    109.  
    110. // imp.
    111. #include <qtimer.h>
    112.  
    113. #include "mainui.h"
    114. #include "filereader.h"
    115.  
    116. MainUI::MainUI(QWidget* parent, const char* name, WFlags fl)
    117. : Form1(parent,name,fl)
    118. {
    119. m_timer = new QTimer(this);
    120.  
    121. connect(m_timer, SIGNAL(timeout()), SLOT(refreshInfo()));
    122.  
    123. m_timer->start( 30000 );
    124.  
    125. fileReader = new FileReader();
    126. fileReader->show();
    127. }
    128.  
    129. void MainUI::refreshInfo()
    130. {
    131. fileReader = new FileReader();
    132. fileReader->show();
    133. }
    134.  
    135.  
    136. // main.cpp
    137. #include <qapplication.h>
    138. #include <qnetwork.h>
    139. #include <stdio.h>
    140. #include <stdlib.h>
    141.  
    142. #include "mainui.h"
    143.  
    144. int main(int argc, char *argv[])
    145. {
    146. QApplication app(argc,argv);
    147.  
    148. qInitNetworkProtocols();
    149.  
    150. MainUI fr;
    151. app.setMainWidget( &fr );
    152. fr.show();
    153.  
    154. app.exec();
    155. }
    To copy to clipboard, switch view to plain text mode 

    thanks for all replys...
    Last edited by hayati; 22nd March 2007 at 20:03. Reason: removed memory leak error

Similar Threads

  1. From extends QTreeWidgetItem emit signal?
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2006, 14:54
  2. Replies: 4
    Last Post: 18th May 2006, 17:48
  3. Replies: 2
    Last Post: 17th May 2006, 21:01
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

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.