Results 1 to 9 of 9

Thread: Console Application to hit different url multiple times within a program

  1. #1
    Join Date
    Mar 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Console Application to hit different url multiple times within a program

    Hi,

    I am trying to write a console application to hit url using QT. I want to have a seperate function (normal C++ function) which does this job. There is a main program that will invoke this function several times (say with different urls) before exiting.

    In order to test this, I tried below changes with the download program under http://harmattan-dev.nokia.com/docs/...-main-cpp.html

    The change I have done to the program is replaced main function with a different function name (say test)
    and written a new main function that will call test. For the first invocation of test everything works as expected
    and if I invoke again the test function without exiting the program, I see segmentation fault.

    QObject::connect: Cannot connect (null)::configurationAdded(QNetworkConfiguration) to QNetworkConfigurationManager::configurationAdded(Q NetworkConfiguration)
    QObject::connect: Cannot connect (null)::configurationRemoved(QNetworkConfiguration ) to QNetworkConfigurationManager::configurationRemoved (QNetworkConfiguration)
    QObject::connect: Cannot connect (null)::configurationUpdateComplete() to QNetworkConfigurationManager::updateCompleted()
    QObject::connect: Cannot connect (null):nlineStateChanged(bool) to QNetworkConfigurationManager:nlineStateChanged(bool)
    QObject::connect: Cannot connect (null)::configurationChanged(QNetworkConfiguration ) to QNetworkConfigurationManager::configurationChanged (QNetworkConfiguration)

    I am very new to QT. Appreciate a way to accompolish this.

  2. #2
    Join Date
    Mar 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Console Application to hit different url multiple times within a program

    Below is the backtrace I see when I try hit the url for the second time without exiting the program.

    #0 0xb6e94e47 in QMutex::lock () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #1 0xb7172be3 in QNetworkConfigurationManagerPrivate::enablePolling () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtNetwork.so.4
    #2 0xb7170dd0 in QNetworkConfigurationManager::QNetworkConfiguratio nManager () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtNetwork.so.4
    #3 0xb713fb7c in QNetworkAccessManager::createRequest () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtNetwork.so.4
    #4 0xb713dea9 in QNetworkAccessManager::get () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtNetwork.so.4
    #5 0x08049df8 in DownloadManager::doDownload ()
    #6 0x0804a738 in DownloadManager::execute ()
    #7 0x0804a8cc in DownloadManager::qt_metacall ()
    #8 0xb6fad50b in QMetaObject::metacall () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #9 0xb6fb87b6 in QMetaCallEvent:laceMetaCall () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #10 0xb6fb97c7 in QObject::event () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #11 0xb6fa7173 in QCoreApplicationPrivate::notify_helper () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #12 0xb6fa71e3 in QCoreApplication::notify () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #13 0xb6fa6d9b in QCoreApplication::notifyInternal () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #14 0xb6fa7936 in QCoreApplicationPrivate::sendPostedEvents () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #15 0xb6fa7b9d in QCoreApplication::sendPostedEvents () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #16 0xb6fd5604 in __gxx_personality_v0 () from /usr/local/Trolltech/Qt-4.7.2/lib/libQtCore.so.4
    #17 0xb6b7fbcd in g_main_context_dispatch () from /opt/gnome/lib/libglib-2.0.so.0
    #18 0xb6b82dcf in __gxx_personality_v0 () from /opt/gnome/lib/libglib-2.0.so.0
    #19 0x080522c0 in ?? ()
    #20 0x00000000 in ?? ()

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Console Application to hit different url multiple times within a program

    Post your actual main() and test() function code.

  4. #4
    Join Date
    Mar 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Console Application to hit different url multiple times within a program

    int test(int argc, char **argv)
    {
    QCoreApplication app(argc, argv);

    DownloadManager manager;
    QTimer::singleShot(0, &manager, SLOT(execute()));

    app.exec();
    }

    int main(int argc, char **argv)
    {
    /* Hit the url for the first time. Everything works fine */
    test(argc, argv);
    /* Hit the same url for second time. Program crashes. It would happen even when a different url is passed*/
    test(argc, argv);
    exit(0);
    }

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Console Application to hit different url multiple times within a program

    The example you started with already allows you to specify multiple URLs on the command line and it will fetch them all.

    Your code is highly unusual: QCoreApplication is intended to a a single instance per program. My guess is that your antique Qt version has issues with there being two QCoreApplication instances (at different times). Your program, nonetheless, does not crash on Qt 4.8.4 Linux but it does download everything on the command line twice.
    Last edited by ChrisW67; 27th March 2013 at 04:16.

  6. #6
    Join Date
    Mar 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Console Application to hit different url multiple times within a program

    Hi,

    Thank your very much for the reply. While I understand that multiple url could be hit at once with the example program, per requirement I have, I do not have all the urls ready at one instance. I have a non-GUI application from where when a new url is posted (it can be posted any number of times through the flow), I will have to fetch data from the url and return control back to application. That is the reason I want to have a seperate function which will hit QT and get the details. I do not want to have a seperate executable for Qt related processing and put main function there.


    I could not find what exactly happens internally upon putting a get request (at line QNetworkReply *reply = manager.get(request). It crashes at that point. Is there a way when I come out of function I can delete QCoreApplication object. Not sure if I can use deleteLater method on QCoreApplication. it did not solve the problem though.

    Thank you for your additional information on that it works with Qt4.8.

    May I ask if there is any other way to handle the same requirement with Qt4.7 in a linux platform?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Console Application to hit different url multiple times within a program

    So just run the example program (unmodified) once for each time your need a URL fetched. I fails to see where the issue is.

    As an aside, you are on a UNIX machine... have you ever heard of wget or curl?

  8. #8
    Join Date
    Mar 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Console Application to hit different url multiple times within a program

    Thanks for the reply.

    As I said in my earlier post, I did not want to have a seperate program to hit the url. Wanted to have it done within main of my application.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Console Application to hit different url multiple times within a program

    You can have as many instances of a downloader class as you want inside your program. You need to read and understand the DownloadManager class code, and modify it to your purpose. You just need to change where DownloadManager::execute() gets the URL to fetch.

Similar Threads

  1. Hiding and showing the same mainwindow multiple times
    By Charvi in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2012, 12:19
  2. Replies: 12
    Last Post: 16th September 2011, 23:48
  3. Replies: 7
    Last Post: 13th September 2011, 13:15
  4. Can I call setRange multiple times for QProgressBar ?
    By elizabeth.h1 in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2010, 07:18
  5. Contex menu appear multiple times
    By kubas in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2009, 14:55

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.