Results 1 to 11 of 11

Thread: QWebView not appearing in function calls

  1. #1
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QWebView not appearing in function calls

    Hello Guys,

    I'm new in QT Programming. Now i'm trying to create a simple browser in QT.
    Here is my requirement in detail

    1. First I need to post some content to a url
    2. Need to receive it's result in text format
    3. If the result is matching my actual string I need to load a url.

    Posting content is working fine and I have received the result in text format.
    Result matching is checking in same function too and if the result is matching the url have to load. but when I execute url is not loading.

    QWebView is not working in my function. It appears for just a fraction of second and gone away. If there is anyotherway to do this please help me.


    Here is my code


    #include <QApplication>
    #include <QtWebKit>
    #include <QNetworkProxy>
    #include <QtGui>
    #include <QNetworkInterface>
    #include <QString>
    #include <QList>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QStringList>
    #include <QUrl>
    #define STR_EQUAL 0

    class DownloadManager: public QObject
    {
    Q_OBJECT
    QNetworkAccessManager manager;
    public:
    public slots:
    void execute();
    void downloadFinished(QNetworkReply *reply);
    };
    void DownloadManager::execute()
    {
    QString text;
    QString arg1;
    arg1 = "http://example.com";
    QUrl url = QUrl::fromEncoded(arg1.toLocal8Bit());
    QNetworkRequest request(url);
    connect(&manager, SIGNAL(finished(QNetworkReply*)),
    SLOT(downloadFinished(QNetworkReply*)));
    QNetworkReply *reply = manager.get(request);
    }

    void DownloadManager::downloadFinished(QNetworkReply *reply)
    {
    QString val1=reply->readAll(); //Receiving url result after get
    QString return_value="xxxxxxxxxxxx"; //text for comparing result of get
    QWebView view;
    if (QString::compare(val1.toAscii().constData(), return_value) == STR_EQUAL) // Checking strings are matching or not
    {
    view.load(QUrl("http://google.com")); //Url that has to be appear in browser
    view.show();
    }
    }

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    DownloadManager manager;
    manager.execute();
    return app.exec();
    QApplication::instance()->quit();
    }
    #include "main.moc"


    Thanks,

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView not appearing in function calls

    Hello there,
    i would say start by reading the forum rules and use code tags for better reading, viewing , and understanding of codes.

  3. #3
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QWebView not appearing in function calls

    Hello,

    Thanks for reply. I have checked many forums but couldn't find the answer. That's why I posted. If you found any forums please let me know.

    Thanks,

  4. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView not appearing in function calls

    You have a great chance finding the right answer on this forum. Its a really helpful forum.
    I meant use code tags , for example, surround your code by [code]
    Qt Code:
    1. your code here
    To copy to clipboard, switch view to plain text mode 
    check out this link Code Tags.

  5. #5
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QWebView not appearing in function calls

    Hello,

    Sorry I didn't get you. if you need my code I have already posted it.

    Thanks

  6. #6
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView not appearing in function calls

    Before your first line of code add: [code]
    After your last line of code add: [code] but add a / before the word code to close it.
    check the link i sent you it explains code tags
    Good luck

  7. #7
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QWebView not appearing in function calls

    Here is the code.


    Qt Code:
    1. #include <QApplication>
    2. #include <QtWebKit>
    3. #include <QNetworkProxy>
    4. #include <QtGui>
    5. #include <QNetworkInterface>
    6. #include <QString>
    7. #include <QList>
    8. #include <QNetworkAccessManager>
    9. #include <QNetworkRequest>
    10. #include <QNetworkReply>
    11. #include <QStringList>
    12. #include <QUrl>
    13. #define STR_EQUAL 0
    14.  
    15. class DownloadManager: public QObject
    16. {
    17. Q_OBJECT
    18. QNetworkAccessManager manager;
    19. public:
    20. public slots:
    21. void execute();
    22. void downloadFinished(QNetworkReply *reply);
    23. };
    24. void DownloadManager::execute()
    25. {
    26. QString text;
    27. QString arg1;
    28. arg1 = "http://example.com";
    29. QUrl url = QUrl::fromEncoded(arg1.toLocal8Bit());
    30. QNetworkRequest request(url);
    31. connect(&manager, SIGNAL(finished(QNetworkReply*)),
    32. SLOT(downloadFinished(QNetworkReply*)));
    33. QNetworkReply *reply = manager.get(request);
    34. }
    35.  
    36. void DownloadManager::downloadFinished(QNetworkReply *reply)
    37. {
    38. QString val1=reply->readAll(); //Receiving url result after get
    39. QString return_value="xxxxxxxxxxxx"; //text for comparing result of get
    40. QWebView view;
    41. if (QString::compare(val1.toAscii().constData(), return_value) == STR_EQUAL) // Checking strings are matching or not
    42. {
    43. view.load(QUrl("http://google.com")); //Url that has to be appear in browser
    44. view.show();
    45. }
    46. }
    47.  
    48. int main(int argc, char **argv)
    49. {
    50. QApplication app(argc, argv);
    51. DownloadManager manager;
    52. manager.execute();
    53. return app.exec();
    54. QApplication::instance()->quit();
    55. }
    56. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView not appearing in function calls

    QWebView is getting out of scope when the method exits.
    Try creating it on a heap not a stack.

  9. #9
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QWebView not appearing in function calls

    Hello,

    I got the problem, but I didn't get the solution. Please help me.

    If there any otherway to post data to a url and get it's result with out using slots and signal. If it's possible it will be very helpfull for me.

    Please let me what i have to do.

    Thanks,

  10. #10
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView not appearing in function calls

    Quote Originally Posted by cmanikandanc
    QWebView is not working in my function. It appears for just a fraction of second and gone away
    you said that the QWebView is showing for a fraction of time , so the slot downloadFinished() is being executed , hence the connect() statement is working as expected.
    Did you try creating the QWebView on heap ?

  11. #11
    Join Date
    Oct 2013
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QWebView not appearing in function calls

    Hello,

    Thanks for reply. Yes I have tried QWebView on heap then I got "Segmentation fault (core dumped)" message while running.
    Actually I have to do some checking and disply a url after getting post/get result. So when connect executes, it terminates after the function. So what i have to for my requirement.

    Thanks

Similar Threads

  1. QWebView load function
    By zgulser in forum Newbie
    Replies: 1
    Last Post: 16th August 2012, 19:52
  2. Replies: 2
    Last Post: 14th July 2012, 04:54
  3. Menu bar not appearing
    By GUIman in forum Newbie
    Replies: 5
    Last Post: 23rd February 2011, 07:00
  4. Replies: 5
    Last Post: 24th October 2010, 06:54
  5. qwt plugin not appearing in qt3
    By gilbertd26 in forum Qwt
    Replies: 2
    Last Post: 5th January 2009, 10:39

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.