Results 1 to 2 of 2

Thread: Problem QTNetwork

  1. #1
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem QTNetwork

    I am getting this getting this error that " QTNetwork , No such file or Directory"

    I took this code dierctly from fortune example, created a new project.
    can anyone explain what went wrong

    Qt Code:
    1. #include <QtGui>
    2. #include <QtNetwork>
    3.  
    4. #include <stdlib.h>
    5.  
    6. #include "server.h"
    7.  
    8. server::server(QWidget *parent)
    9. : QDialog(parent), tcpServer(0), networkSession(0)
    10. {
    11. statusLabel = new QLabel;
    12. quitButton = new QPushButton(tr("Quit"));
    13. quitButton->setAutoDefault(false);
    14.  
    15.  
    16. QNetworkConfigurationManager manager;
    17. if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
    18. // Get saved network configuration
    19. QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
    20. settings.beginGroup(QLatin1String("QtNetwork"));
    21. const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
    22. settings.endGroup();
    23.  
    24. // If the saved network configuration is not currently discovered use the system default
    25. QNetworkConfiguration config = manager.configurationFromIdentifier(id);
    26. if ((config.state() & QNetworkConfiguration::Discovered) !=
    27. QNetworkConfiguration::Discovered) {
    28. config = manager.defaultConfiguration();
    29. }
    30.  
    31. networkSession = new QNetworkSession(config, this);
    32. connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
    33.  
    34. statusLabel->setText(tr("Opening network session."));
    35. networkSession->open();
    36. } else {
    37. sessionOpened();
    38. }
    39.  
    40. //! [2]
    41. fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
    42. << tr("You've got to think about tomorrow.")
    43. << tr("You will be surprised by a loud noise.")
    44. << tr("You will feel hungry again in another hour.")
    45. << tr("You might have mail.")
    46. << tr("You cannot kill time without injuring eternity.")
    47. << tr("Computers are not intelligent. They only think they are.");
    48. //! [2]
    49.  
    50. connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    51. //! [3]
    52. connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
    53. //! [3]
    54.  
    55. QHBoxLayout *buttonLayout = new QHBoxLayout;
    56. buttonLayout->addStretch(1);
    57. buttonLayout->addWidget(quitButton);
    58. buttonLayout->addStretch(1);
    59.  
    60. QVBoxLayout *mainLayout = new QVBoxLayout;
    61. mainLayout->addWidget(statusLabel);
    62. mainLayout->addLayout(buttonLayout);
    63. setLayout(mainLayout);
    64.  
    65. setWindowTitle(tr("Fortune Server"));
    66. }
    To copy to clipboard, switch view to plain text mode 



    Header is:::


    Qt Code:
    1. #ifndef SERVER_H
    2. #define SERVER_H
    3.  
    4. #include <QDialog>
    5. QT_BEGIN_NAMESPACE
    6. class QLabel;
    7. class QTcpServer;
    8. class QNetworkSession;
    9. QT_END_NAMESPACE
    10.  
    11.  
    12. class server : public QDialog
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. server(QWidget *parent = 0);
    18.  
    19.  
    20. private:
    21. void sessionOpened();
    22. void sendFortune();
    23. QLabel *statusLabel;
    24. QPushButton *quitButton;
    25. QTcpServer *tcpServer;
    26. QStringList fortunes;
    27. QNetworkSession *networkSession;
    28.  
    29. };
    30.  
    31. #endif // SERVER_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem QTNetwork

    What is about your .pro file?
    Added the network to the QT-variable?

    Qt Code:
    1. QT += gui core network
    To copy to clipboard, switch view to plain text mode 
    develboard.blogspot.com - Private German Blog and Wiki about Qt and Linux related Stuff

  3. The following user says thank you to ghal maraz for this useful post:

    Arpitgarg (11th March 2011)

Similar Threads

  1. Including QtNetwork
    By treyweaver in forum Newbie
    Replies: 2
    Last Post: 3rd January 2011, 15:42
  2. QtNetwork Performance
    By ngenen in forum Qt Programming
    Replies: 5
    Last Post: 25th November 2010, 19:08
  3. qmake and QtNetwork
    By gt.beta2 in forum Newbie
    Replies: 6
    Last Post: 15th March 2009, 00:46
  4. QtNetwork
    By wagui in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 22:54
  5. Replies: 2
    Last Post: 8th September 2006, 12:35

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.