Results 1 to 10 of 10

Thread: Not getting proper response in slot connected with QNetworkAccessManager second time

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,329
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Not getting proper response in slot connected with QNetworkAccessManager second t

    QCoreApplication QCoreApplication(argc, argv);
    I hope this is just a bad cut and paste job, because I have no idea what you intend this line of code to do.

  2. #2
    Join Date
    Aug 2015
    Posts
    5
    Platforms
    Windows

    Default Re: Not getting proper response in slot connected with QNetworkAccessManager second t

    I am not finding any way to create thread only once and send request in already running thread because the function which is calling pthread_create needs to be called by below function. Calling of this function can't be handled. This function is called every time whenever a button is clicked from javascript application.

    Qt Code:
    1. string TemplateJS::InvokeMethod(const string& command) {
    2. // command appears with parameters following after a space
    3. int index = command.find_first_of(" ");
    4. std::string strCommand = command.substr(0, index);
    5. std::string arg = command.substr(index + 1, command.length());
    6. params = arg;
    7. if (strCommand == "request") {
    8. StartThread();
    9.  
    10. strCommand.append(";");
    11. strCommand.append(command);
    12. return strCommand;
    13. }
    14.  
    15. return "Unknown C++ method";
    16. }
    To copy to clipboard, switch view to plain text mode 

    if I call m_signalHandler->doNetworkRequest(); two times in SignalThread then it's working fine and returns good response. But if I call StartThread() two times in above function, app exits.


    Added after 10 minutes:


    Quote Originally Posted by d_stranz View Post
    I hope this is just a bad cut and paste job, because I have no idea what you intend this line of code to do.
    I have changed it to
    Qt Code:
    1. QCoreApplication app(argc, argv);
    To copy to clipboard, switch view to plain text mode 

    Also according to document since exec() is static function of QCoreApplication so it can be called like: QCoreApplication::exec();

    Please correct me if something is wrong. As I am new to this.
    Last edited by BB_Shi; 7th August 2015 at 13:06.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Not getting proper response in slot connected with QNetworkAccessManager second t

    Quote Originally Posted by BB_Shi View Post
    I am not finding any way to create thread only once and send request in already running thread because the function which is calling pthread_create needs to be called by below function.
    You would of course only call the setup function once.

    Once the thread and its event loop are running, you have a couple of options to send the requests:
    - QCoreApplication:ostEvent and a custom event sent to your worker object.
    - Or letting the worker object block on a semaphore or wait condition and doing traditional cross-thread data handover.
    - Might even work to do QMetaObject::invokeMethod on the worker object (using a Qt::QueuedConnection type)

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 21st November 2014, 08:14
  2. Slot connected to a generic signal
    By Momergil in forum Qt Programming
    Replies: 5
    Last Post: 28th June 2014, 22:42
  3. Replies: 11
    Last Post: 2nd February 2013, 14:39
  4. Replies: 2
    Last Post: 26th August 2011, 08:51
  5. Disconnect slot when another is being connected
    By holst in forum Qt Programming
    Replies: 4
    Last Post: 8th September 2009, 09:49

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.