本文整理汇总了C++中QNetworkConfiguration类的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkConfiguration类的具体用法?C++ QNetworkConfiguration怎么用?C++ QNetworkConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QObject
Server::Server(QObject *parent) :
QObject(parent), tcpServer(0), networkSession(0), memBuf(NULL)
{
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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()));
QTextStream out(stdout);
out << tr("Opening network session.");
networkSession->open();
} else {
sessionOpened();
}
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendImage()));
}
示例2: openConnection
bool Network::openConnection(QString &netInterface)
{
// Internet Access Point
QNetworkConfigurationManager manager;
const bool canStartIAP = (manager.capabilities()
& QNetworkConfigurationManager::CanStartAndStopInterfaces);
// If there is a default access point, use it
QNetworkConfiguration cfg = manager.defaultConfiguration();
if (!cfg.isValid() || !canStartIAP) {
return false;
}
// Open session
m_session = new QNetworkSession(cfg);
m_session->open();
// Waits for session to be open and continues after that
m_session->waitForOpened();
// Show interface name to the user
QNetworkInterface iff = m_session->interface();
netInterface = iff.humanReadableName();
return true;
}
示例3: settings
Server::Server()
{
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
{
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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);
if (networkSession)
{
connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
TRACE_INFO(NET, "Opening network session...\n");
networkSession->open();
}
}
else
{
sessionOpened();
}
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.");
if (tcpServer)
{
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendDatas()));
}
/*
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
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"));
*/
}
示例4: QLOG_DEBUG
int OcNetwork::bearerType()
{
QNetworkConfiguration netConf = this->activeConfiguration();
QLOG_DEBUG() << "Network bearer type name: " << netConf.bearerTypeName();
QNetworkConfiguration::BearerType bt;
bt = netConf.bearerType();
int btNum;
switch (bt) {
case QNetworkConfiguration::BearerEthernet:
case QNetworkConfiguration::BearerWLAN:
btNum = 1;
break;
case QNetworkConfiguration::Bearer2G:
case QNetworkConfiguration::BearerCDMA2000:
case QNetworkConfiguration::BearerWCDMA:
case QNetworkConfiguration::BearerHSPA:
btNum = 2;
break;
case QNetworkConfiguration::BearerUnknown:
default:
btNum = 0;
break;
}
return btNum;
}
示例5: networkSession_
BigBlobbyClient::BigBlobbyClient() :
networkSession_( NULL ),
tcpSocket_( new QTcpSocket( this ) ),
portNumber_( DEFAULT_PORT_NUMBER ),
log_( logger::FileLogger::instance() )
{
connect( tcpSocket_, SIGNAL( readyRead() ), this, SLOT( readBigBlobbyResponse() ) );
connect( tcpSocket_, SIGNAL( error( QAbstractSocket::SocketError ) ),
this, SLOT( displayError( QAbstractSocket::SocketError ) ) );
QNetworkConfigurationManager manager;
if( manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired ) {
// Get saved network configuration
QSettings settings( QSettings::UserScope, QLatin1String( "BigBlobby" ) );
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() ) );
networkSession_->open();
}
}
示例6: QObject
TcpEchoServer::TcpEchoServer(quint16 port, QObject *parent)
: QObject(parent), tcpServer(0), networkSession(0)
{
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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()));
qDebug() << "Opening network session.";
networkSession->open();
} else {
sessionOpened(port);
}
}
示例7: sessionOpened
void Server::sessionOpened()//change ip address here
{
// Save the used configuration
if (networkSession) {
QNetworkConfiguration config = networkSession->configuration();
QString id;
if (config.type() == QNetworkConfiguration::UserChoice)
id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
else
id = config.identifier();
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
settings.beginGroup(QLatin1String("QtNetwork"));
settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
settings.endGroup();
}
tcpServer = new QTcpServer(this);
// if (!tcpServer->listen(QHostAddress::LocalHost,PORT)) {
if (!tcpServer->listen()) {
QMessageBox::critical(this, tr("Fortune Server"),
tr("Unable to start the server: %1.")
.arg(tcpServer->errorString()));
close();
return;
}
QString ipAddress = IP_ADDRESS;
// if we did not find one, use IPv4 localhost
if (ipAddress.isEmpty())
ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
qDebug() << "The server is running on:\nIP:"<< ipAddress <<"\nPort:"<< tcpServer->serverPort() <<"\n";
}
示例8: foreach
foreach(const QNetworkConfiguration p, configs) {
printConfigurationDetails(p);
QVERIFY(p.isValid());
QVERIFY(!(p.state() & QNetworkConfiguration::Undefined));
QVERIFY(p.state() & QNetworkConfiguration::Defined);
QVERIFY(p.state() & QNetworkConfiguration::Discovered);
}
示例9: networkSession
Client::Client(QString purpose) : networkSession(0)
{
Client::purpose = purpose;
tcpSocket = new QTcpSocket;
Client::blockSize = 0;
qDebug() << connect(tcpSocket, &QTcpSocket::readyRead, this, &Client::readData);
//connect(tcpSocket, &QTcpSocket::error, this, &Client::displayError);
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
{
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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);
qDebug() << connect(networkSession, &QNetworkSession::opened, this, &Client::sessionOpened);
}
qDebug() << "Client set up, waiting";
}
示例10: write_message
void Server::StartServer()
{
shotTimer->stop();
is_config_mode = false;
emit write_message(tr("Network session starting."));
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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(sessionOpen()));
emit write_message(tr("Opening network session."));
networkSession->open();
} else {
sessionOpen();
}
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(recieveConnection()));
}
示例11: settings
void lc::ClientHelpNotificationServer::OpenSession() {
// Save the used configuration
if ( networkSession ) {
QNetworkConfiguration config = networkSession->configuration();
QString id;
if ( config.type() == QNetworkConfiguration::UserChoice ) {
id = networkSession->sessionProperty( QLatin1String{ "UserChoiceConfiguration" } ).toString();
} else {
id = config.identifier();
}
QSettings settings( QSettings::UserScope, QLatin1String{ "QtProject" } );
settings.beginGroup( QLatin1String{ "QtNetwork" } );
settings.setValue( QLatin1String{ "DefaultNetworkConfiguration" }, id );
settings.endGroup();
}
helpMessageServer = new QTcpServer{ this };
if ( !helpMessageServer->listen( hostAddress, settings->clientHelpNotificationServerPort ) ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Unable to start the client help notification server" ),
tr( "Unable to start the client help notification server.\nThe following error occurred:\n\n%1." ).arg( helpMessageServer->errorString() ), QMessageBox::Ok };
messageBox.exec();
return;
}
}
示例12: networkSession
/*!
Starts the backend. Returns \c true if the backend is started. Returns \c false if the backend
could not be started due to an unopened or roaming session. The caller should recall this
function once the session has been opened or the roaming process has finished.
*/
bool QNetworkAccessBackend::start()
{
#ifndef QT_NO_BEARERMANAGEMENT
// For bearer, check if session start is required
QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession());
if (networkSession) {
// session required
if (networkSession->isOpen() &&
networkSession->state() == QNetworkSession::Connected) {
// Session is already open and ready to use.
// copy network session down to the backend
setProperty("_q_networksession", QVariant::fromValue(networkSession));
} else {
// Session not ready, but can skip for loopback connections
// This is not ideal.
const QString host = reply->url.host();
if (host == QLatin1String("localhost") ||
QHostAddress(host).isLoopback() ||
reply->url.isLocalFile()) {
// Don't need an open session for localhost access.
} else {
// need to wait for session to be opened
return false;
}
}
}
#endif
#ifndef QT_NO_NETWORKPROXY
#ifndef QT_NO_BEARERMANAGEMENT
// Get the proxy settings from the network session (in the case of service networks,
// the proxy settings change depending which AP was activated)
QNetworkSession *session = networkSession.data();
QNetworkConfiguration config;
if (session) {
QNetworkConfigurationManager configManager;
// The active configuration tells us what IAP is in use
QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration"));
if (v.isValid())
config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v));
// Fallback to using the configuration if no active configuration
if (!config.isValid())
config = session->configuration();
// or unspecified configuration if that is no good either
if (!config.isValid())
config = QNetworkConfiguration();
}
reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url()));
#else // QT_NO_BEARERMANAGEMENT
// Without bearer management, the proxy depends only on the url
reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url()));
#endif
#endif
// now start the request
open();
return true;
}
示例13: QDialog
Server::Server(QWidget *parent) : QDialog(parent)
{
networkSession=0;
tcpServer=0;
ui = new Ui::Server;
ui->setupUi(this);
val=0;
ui->quit_button->setAutoDefault(false);
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
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()));
networkSession->open();
} else {
sessionOpened();
}
connect(ui->quit_button, SIGNAL(clicked()), this, SLOT(close()));
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(conn()));
}
示例14: connect
lc::ClientHelpNotificationServer::ClientHelpNotificationServer( QObject *argParent ) :
QObject{ argParent },
hostAddress{ settings->serverIP }
{
QNetworkConfigurationManager manager;
if ( manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired ) {
// Get saved network configuration
QSettings settings{ QSettings::UserScope, QLatin1String{ "QtProject" } };
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, &QNetworkSession::opened,
this, &ClientHelpNotificationServer::OpenSession );
networkSession->open();
} else {
OpenSession();
}
connect( helpMessageServer, &QTcpServer::newConnection,
this, &ClientHelpNotificationServer::SendReply );
}
示例15: assert
bool TCPClientProducer::init()
{
assert( m_networkSession == 0 );
assert( m_tcpSocket != 0 );
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
{
// 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();
}
m_networkSession = new QNetworkSession(config);
connect(m_networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
qDebug() << "Opening network session.";
m_networkSession->open();
}
return true;
}