Results 1 to 4 of 4

Thread: Networking classes need QWidget?

  1. #1
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Networking classes need QWidget?

    Can someone please explain why on God's green earth the network classes __need__ GUI QWidget resources?

    This makes them completely unusable from a console app.

    Has someone filed a bug?

  2. #2
    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: Networking classes need QWidget?

    Can someone please explain why on God's green earth the network classes __need__ GUI QWidget resources?
    What makes you think they do? QtNetwork4 is not dependent on QtGui4 on my machine.
    This makes them completely unusable from a console app.
    Really? This program compiles and runs fine without Gui:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtNetwork>
    3. #include <QDebug>
    4.  
    5. class Fetcher: public QObject {
    6. Q_OBJECT
    7. public:
    8. Fetcher(QObject *p = 0): QObject(p), reply(0) {}
    9.  
    10. void fetch(const QUrl &url) {
    11. reply = nam.get(QNetworkRequest(url));
    12. connect(reply, SIGNAL(finished()), SLOT(slotFinished()));
    13. }
    14.  
    15. public slots:
    16. void slotFinished() {
    17. qDebug() << Q_FUNC_INFO << "Error" << reply->error();
    18. QByteArray ba = reply->readAll();
    19. qDebug() << ba;
    20. reply->deleteLater();
    21.  
    22. emit finished();
    23. }
    24. signals:
    25. void finished();
    26. private:
    27. QNetworkAccessManager nam;
    28. QNetworkReply *reply;
    29. };
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QCoreApplication app(argc, argv);
    34.  
    35. Fetcher f;
    36. f.fetch(QUrl("http://www.qtcentre.org/robots.txt"));
    37. QObject::connect(&f, SIGNAL(finished()), qApp, SLOT(quit()));
    38.  
    39. return app.exec();
    40. }
    41. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    It has "QT -= gui" in the PRO file and is consequently not linked to QtGui4.
    Has someone filed a bug?
    Plenty of people have filed bugs. This is not a bug though.

  3. #3
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Networking classes need QWidget?

    Try adding QWebPage and QWebElementCollection. Even though you turn everything off and have it set to display absolutely nothing, it still needs the GUI. Why would anyone do this? To identify/verify site content with a crawler on a server.

  4. #4
    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: Networking classes need QWidget?

    QtWebkit is a Qt-esque wrapper around the Webkit browser (not crawler) library. If you use Webkit or QtWebkit, which has a browser widget whether you use it or not, then you need the rendering library (QtGUI in this case). QWebPage has a bunch of GUI rendering functionality that you cannot avoid. If you don't like it, don't use QtWebkit or do the work to separate non-GUI from GUI components of WebKit and contribute it to the community. Depending on your exact requirements there are other ways to go about parsing the muck called HTML.

    This makes them completely unusable from a console app.
    Only partly true. You have to use QApplication but you do not need to display a GUI. On Linux X11 libraries must be present, and you can fake a running X server with Xvfb. For example, a headless QtWebKit program that extracts image links from www.google.com:
    Qt Code:
    1. $ unset DISPLAY
    2. $ ./grab
    3. grab: cannot connect to X server
    4. $ Xvfb 2>/dev/null >&2 :10 &
    5. $ DISPLAY=:10 ./grab
    6. Image at: "/images/icons/product/chrome-48.png"
    7. Image at: "/logos/2012/montessori-hp.jpg"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 16th September 2010, 16:57
  2. change QWidget from QThread classes
    By radeberger in forum Qt Programming
    Replies: 12
    Last Post: 30th May 2010, 20:45
  3. QT non-gui networking
    By MAbeeTT in forum Newbie
    Replies: 1
    Last Post: 21st August 2009, 20:47
  4. Qt-3 and networking
    By a550ee in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2006, 12:15
  5. Networking Help please
    By munna in forum Newbie
    Replies: 1
    Last Post: 17th September 2006, 10:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.