Results 1 to 17 of 17

Thread: QUrlOperator doesn't emit finished signal

Hybrid 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrlOperator doesn't emit finished signal

    Maybe it's because of a memory leak? Where do you delete m_op?

  3. #3
    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 Re: QUrlOperator doesn't emit finished signal

    yeh i know there is (or are) memory leak. but the problem isn't the memory leak. As you see from the code it just shows the skeleton, in actual program it is deleted but there is no change.
    After all even there is a memory leak m_op is created from the beginning. so newly created m_op should get finished signal either way. I applied with the delete m_op but this didn't changed any thing
    everbody is free to change the code to make it worked. As skeleton shows there isn't any magic operation took place. Amazingly it doesn't emit finished.

    i also edited the source code to fix the leak.

    what i also tried to stop get progres before to delete m_op with
    Qt Code:
    1. m_op->stop();
    To copy to clipboard, switch view to plain text mode 
    at the destructor but it also makes no sense
    Last edited by hayati; 22nd March 2007 at 20:06.

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

    Exclamation Re: QUrlOperator doesn't emit finished signal

    Unfortunately i get neither descriptive reason of the problem nor solution to it.
    As the code part of my problem shows, it should be worked but it isn't.
    Any help is wellcome.

    here is what i get at the console output:
    conn state changed to: host asdfasdf found
    finished but there is an error...
    conn state changed to: host asdfasdf found
    finished but there is an error...
    conn state changed to: host asdfasdf found
    finished but there is an error...
    conn state changed to: host asdfasdf found
    finished but there is an error...
    conn state changed to: host asdfasdf found
    conn state changed to: host asdfasdf found
    conn state changed to: host asdfasdf found
    conn state changed to: host asdfasdf found
    conn state changed to: host asdfasdf found
    conn state changed to: host asdfasdf found

    this goes forever...

    as output shows after a while finished signal is not emitted
    Last edited by hayati; 23rd March 2007 at 09:25.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrlOperator doesn't emit finished signal

    Quote Originally Posted by hayati View Post
    as output shows after a while finished signal is not emitted
    How long does this "while" take? Which Qt version do you use?

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

    Unhappy Re: QUrlOperator doesn't emit finished signal

    i use qt3
    and from the output it could be said that it's about 120 to 210 seconds at least but it could take long of course because there is no clue about the error. I'm using just the code i've posted to test the situation but even this little code makes the same error.
    i think it's goint to a qt bug
    because it works perfectly when requested web pages are found.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrlOperator doesn't emit finished signal

    Quote Originally Posted by hayati View Post
    i use qt3
    There are over 20 versions of Qt3. Which one do you use?

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

    Exclamation Re: QUrlOperator doesn't emit finished signal

    right it's v3.3.6

    and v3.3.3 gives the same result
    Last edited by hayati; 23rd March 2007 at 12:28.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrlOperator doesn't emit finished signal

    Quote Originally Posted by hayati View Post
    right it's v3.3.6

    and v3.3.3 gives the same result
    Try Qt 3.3.8. There was some problem with QDns fixed. On my system finished() is always emitted, but the application crashes after a while (it has something to do with event delivery).

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

    Exclamation Re: QUrlOperator doesn't emit finished signal

    thanks for the reply,
    yes it's obvious that it has some problems internally.
    unfortunately i can't use v3.3.8
    even so, as you said it gets errors with internal SIGSEGV errors.
    I'll use libcurl library for that purpose for now
    thanks for help.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QUrlOperator doesn't emit finished signal

    Quote Originally Posted by hayati View Post
    even so, as you said it gets errors with internal SIGSEGV errors.
    I didn't say that they are internal errors.

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.