Results 1 to 5 of 5

Thread: Are QHttp n QHttpRequestHeader thread safe?

  1. #1
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Are QHttp n QHttpRequestHeader thread safe?

    I am using Qt 4.1 and want to post to server from the threads. Is this possible?

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Are QHttp n QHttpRequestHeader thread safe?

    yes
    can you give more information about your task?

  3. #3
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Are QHttp n QHttpRequestHeader thread safe?

    Sure. Mt requirement here is to simulate an environment where 'n' end systems are simultaneuosly posting x requests each, to a server.

    I have a class, Http, which implements sending x requests to the server as follows using the QHttp n QHttpRequestHeader.

    The constructor of this class has
    Qt Code:
    1. QHttp op=new QHttp();
    2. op->setHost(192.168.0.89);
    To copy to clipboard, switch view to plain text mode 

    while a function info() of the same class, implements
    Qt Code:
    1. QHttpRequestHeader header( "POST", "server.php" ) ;
    2. header.setValue( "Host", "192.168.0.89" ) ;
    3. header.setContentType( "application/x-www-form-urlencoded" ) ;
    4. op->request(header,logData);
    To copy to clipboard, switch view to plain text mode 

    I tested this and it is working perfectly.Now in order to get n systems doing this simultaneously, I am using a class inherited from QThread. I have reimplemented run() to create a Http object and call info().

    In the main(), i have
    Qt Code:
    1. QList <MyThread *> list;
    2. for(int i=0;i<noOfThreads;i++)
    3. {
    4. MyThread *t = new MyThread(noOfLogs);
    5. list.append(t);
    6. QObject::connect(t, SIGNAL(finished()),t, SLOT(deleteLater()));
    7. t->start();
    8. }
    To copy to clipboard, switch view to plain text mode 

    This does not work, not a single request is sent. However if i call run() instead of start(), it works. But i guess, i should not be calling run() as then each thread will be created one after the other i the loop, which beats simultaneous requirement.

    I however tried
    Qt Code:
    1. QObject::connect(t, SIGNAL(finished()),t, SLOT(CallRun()));
    To copy to clipboard, switch view to plain text mode 
    Then the exe, works with a call to start().

    Can you point where i am probably going wrong?

    Thanks a lot in advance.

  4. #4
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Are QHttp n QHttpRequestHeader thread safe?

    Quote Originally Posted by Shambhavi
    I have reimplemented run() to create a Http object and call info().
    Can you show us run()? You may need to start an event loop in every thread.

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Are QHttp n QHttpRequestHeader thread safe?

    Hm maiby available some errors in declaring MyThread?Show your *.h file pls.
    What will happen if you start only one thread without cycle? Have your run() is exceuting?

Similar Threads

  1. What makes something not thread safe?
    By tgreaves in forum Newbie
    Replies: 9
    Last Post: 20th February 2009, 20:16
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19
  4. QHttp in thread (QT4)
    By maxpower in forum Qt Programming
    Replies: 15
    Last Post: 21st February 2007, 18:55
  5. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49

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.