PDA

View Full Version : Problem QTNetwork



Arpitgarg
11th March 2011, 04:23
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


#include <QtGui>
#include <QtNetwork>

#include <stdlib.h>

#include "server.h"

server::server(QWidget *parent)
: QDialog(parent), tcpServer(0), networkSession(0)
{
statusLabel = new QLabel;
quitButton = new QPushButton(tr("Quit"));
quitButton->setAutoDefault(false);


QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequir ed) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
settings.beginGroup(QLatin1String("QtNetwork"));
const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
settings.endGroup();

// If the saved network configuration is not currently discovered use the system default
QNetworkConfiguration config = manager.configurationFromIdentifier(id);
if ((config.state() & QNetworkConfiguration::Discovered) !=
QNetworkConfiguration::Discovered) {
config = manager.defaultConfiguration();
}

networkSession = new QNetworkSession(config, this);
connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));

statusLabel->setText(tr("Opening network session."));
networkSession->open();
} else {
sessionOpened();
}

//! [2]
fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
<< tr("You've got to think about tomorrow.")
<< tr("You will be surprised by a loud noise.")
<< tr("You will feel hungry again in another hour.")
<< tr("You might have mail.")
<< tr("You cannot kill time without injuring eternity.")
<< tr("Computers are not intelligent. They only think they are.");
//! [2]

connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
//! [3]
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
//! [3]

QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
buttonLayout->addWidget(quitButton);
buttonLayout->addStretch(1);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(statusLabel);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);

setWindowTitle(tr("Fortune Server"));
}




Header is:::



#ifndef SERVER_H
#define SERVER_H

#include <QDialog>
QT_BEGIN_NAMESPACE
class QLabel;
class QPushButton;
class QTcpServer;
class QNetworkSession;
QT_END_NAMESPACE


class server : public QDialog
{
Q_OBJECT

public:
server(QWidget *parent = 0);


private:
void sessionOpened();
void sendFortune();
QLabel *statusLabel;
QPushButton *quitButton;
QTcpServer *tcpServer;
QStringList fortunes;
QNetworkSession *networkSession;

};

#endif // SERVER_H

ghal maraz
11th March 2011, 06:20
What is about your .pro file?
Added the network to the QT-variable?


QT += gui core network