Results 1 to 17 of 17

Thread: QUrlOperator doesn't emit finished signal

  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 21: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 21: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 10: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 13: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.

  12. #12
    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

    yes you didn't say, sorry about misunderstanding.
    I'm confused because i get SIGSEGV after my last try to fix the problem
    That's why i said SIGSEGV, it's what i get, not yours.
    If it's undertood like yours i apologize

    Another amazing thing about the QUrlOperator is;
    I placed a single-shot timer as error-interval. When timer is up then even if i don't get finished signal i delete the opened widget, at the destructor i stop m_op, and delete it.
    But this time i got SIGSEGV.
    In addition, gdb stack trace points out qsocket caused the SIGSEGV.
    that's why i said -INTERNAL- error.
    I think I get SIGSEGV because m_op opened a QSocket internally but after i delete m_op then m_op deletes QSocket and when system is about to use to deleted socket then SIGSEGV occurs. (just an estimation)
    By the way that's not the point of the problem.

    Problem is QUrlOperator doesn't emit finished signals after a while
    Last edited by hayati; 23rd March 2007 at 15:32.

  13. #13
    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
    But this time i got SIGSEGV.
    Such fault can occur when you delete an object within event handler and it's usually solved using QObject::deleteLater().

    Quote Originally Posted by hayati View Post
    Problem is QUrlOperator doesn't emit finished signals after a while
    It looks like this problem doesn't occur on Qt 3.3.8. Try the narrowed-down example from the attachment.
    Attached Files Attached Files

  14. #14
    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 your quick replys. I really appreciated.
    I couldn't answer your replys for a while because i got cold.
    Unfortunately even v3.3.8 with your test code(main.cpp) fails when id is over 400.
    After id value of 400, program didn't received any finished signal at all
    Perharps you didn't wait as much as program starts failing
    Because we don't know what is wrong and when the program starts failing best of best of us is to wait for ten minutes at least.
    I am sure that my application uses v3.3.8 because i checked it with qVersion() within your test code.

  15. #15
    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
    Unfortunately even v3.3.8 with your test code(main.cpp) fails when id is over 400.
    After id value of 400, program didn't received any finished signal at all
    I've just tried it again and reached id = 1500 without any signs of failure.

    I can't run Valgrind on my system, so I can't check whether the are any problems inside Qt, but try this:
    Qt Code:
    1. Test() : _id( _nextId++ )
    2. {
    3. std::cerr << "created " << _id << std::endl;
    4. _op = new QUrlOperator("http://test.domain.tld/");
    5.  
    6. if( _op != 0 ) {
    7. connect( _op, SIGNAL(finished(QNetworkOperation*)), SLOT(finished()) );
    8. if( _op->get() == 0 ) {
    9. std::cerr << "get() failed " << _id << std::endl;
    10. deleteLater();
    11. }
    12. }
    13. else {
    14. std::cerr << "allocation failed " << _id << std::endl;
    15. deleteLater();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

  16. The following user says thank you to jacek for this useful post:

    hayati (26th March 2007)

  17. #16
    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

    It's about something different.
    I tested main.cpp in my home network then it's like just you mentioned.
    So it works perfectly even with v3.3.6 at my home. But what's missing with my job network or what's more.
    My home network is very little it has three pc so name resolution could be very fast.
    But my job network is quite big (and more will be- over 400 pc).
    It has a heavy multicast traffic also. (But I don't think that's the problem) It must be something different. At first I thought it might be a protection from firewall or other network devices (just an estimation), but my network admin said it isn't.
    But unfortunately I have no idea
    By the way I started coding my own url class from curl.
    Even if I know that qt has coded it more bugfree than me, I have no other chance to do now unless finding out the way to make it worked.

    Thanks for your patience, because I give up counting at 1265 an I satisfied that it's something else

  18. #17
    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
    But my job network is quite big (and more will be- over 400 pc).
    It has a heavy multicast traffic also.
    Then it might be some subtle bug that might possibly have something to do with timeouts. You can try contacting Trolltech and ask whether they can do something about it.

Similar Threads

  1. From extends QTreeWidgetItem emit signal?
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2006, 15:54
  2. Replies: 4
    Last Post: 18th May 2006, 18:48
  3. Replies: 2
    Last Post: 17th May 2006, 22:01
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 17:36
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 12: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.