本文整理汇总了C++中QNetworkSession::configuration方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkSession::configuration方法的具体用法?C++ QNetworkSession::configuration怎么用?C++ QNetworkSession::configuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkSession
的用法示例。
在下文中一共展示了QNetworkSession::configuration方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
/*!
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;
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
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();
}
QNetworkSession *networkSession = new QNetworkSession(config, &app);
networkSession->open();
networkSession->waitForOpened();
if (networkSession->isOpen()) {
// Save the used configuration
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("Trolltech"));
settings.beginGroup(QLatin1String("QtNetwork"));
settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
settings.endGroup();
}
}
//ChatDialog dialog;
InitialWindow window;
#ifdef Q_OS_SYMBIAN
// Make application better looking and more usable on small screen
// dialog.showMaximized();
#else
// dialog.show();
window.show();
#endif
return app.exec();
}
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
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();
}
QNetworkSession *networkSession = new QNetworkSession(config, &a);
networkSession->open();
networkSession->waitForOpened();
if (networkSession->isOpen()) {
// Save the used configuration
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();
}
}
interface w;
w.show();
return a.exec();
}
示例4: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
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();
}
QNetworkSession *networkSession = new QNetworkSession(config, &a);
networkSession->open();
networkSession->waitForOpened();
if (networkSession->isOpen()) {
// Save the used configuration
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("Trolltech"));
settings.beginGroup(QLatin1String("QtNetwork"));
settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
settings.endGroup();
}
}
RedDeerNote w;
QSplashScreen *splash=new QSplashScreen;
splash->setPixmap(QPixmap(":/icons/logord2.png"));
splash->show();
splash->showMessage( "Initializing..." );
SleeperThread::msleep(300);
splash->showMessage( "Load GUI..." );
SleeperThread::msleep(300);
splash->showMessage( "Load Library..." );
SleeperThread::msleep(300);
splash->showMessage( "Starting..." );
SleeperThread::msleep(300);
w.show();
splash->finish(&w);
delete splash;
return a.exec();
}