本文整理汇总了C++中QNetworkConfiguration::state方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkConfiguration::state方法的具体用法?C++ QNetworkConfiguration::state怎么用?C++ QNetworkConfiguration::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkConfiguration
的用法示例。
在下文中一共展示了QNetworkConfiguration::state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: networkConfigurationChanged
/** @short Some of the configuration profiles have changed
This can be some completely harmelss change, like user editting an inactive profile of some random WiFi network.
Unfortunately, this is also the only method in which the Qt's NetworkManager plugin informs us about a switch
from eth0 to wlan0.
There's apparently no better signal, see http://lists.qt-project.org/pipermail/interest/2013-December/010374.html
*/
void SystemNetworkWatcher::networkConfigurationChanged(const QNetworkConfiguration &conf)
{
bool reconnect = false;
if (conf == sessionsActiveConfiguration() && !conf.state().testFlag(QNetworkConfiguration::Active) &&
conf != m_netConfManager->defaultConfiguration() && m_netConfManager->defaultConfiguration().isValid()) {
// Change of the "session's own configuration" which is not a default config of the system (anymore?), and the new default
// is something valid.
// I'm seeing (Qt 5.5-git, Linux, NetworkManager,...) quite a few of these as false positives on a random hotel WiFi.
// Let's prevent a ton of useless reconnects here by only handling this if the system now believes that a default session
// is something else.
m_model->logTrace(0, Common::LOG_OTHER, QStringLiteral("Network Session"),
QStringLiteral("Change of configuration of the current session (%1); current default session is %2")
.arg(conf.name(), m_netConfManager->defaultConfiguration().name()));
reconnect = true;
} else if (conf.state().testFlag(QNetworkConfiguration::Active) && conf.type() == QNetworkConfiguration::InternetAccessPoint &&
conf != sessionsActiveConfiguration() && conf == m_netConfManager->defaultConfiguration()) {
// We are going to interpret this as a subtle hint for switching to another session
if (m_session->configuration().type() == QNetworkConfiguration::UserChoice && !sessionsActiveConfiguration().isValid()) {
// No configuration has been assigned yet, just ignore this event. This happens on Harmattan when we get a change
// of e.g. an office WiFi connection in reply to us trying to open a session with the system's default configuration.
m_model->logTrace(0, Common::LOG_OTHER, QStringLiteral("Network Session"),
QStringLiteral("No configuration has been assigned yet, let's wait for it"));
return;
}
m_model->logTrace(0, Common::LOG_OTHER, QStringLiteral("Network Session"),
m_session->configuration().type() == QNetworkConfiguration::InternetAccessPoint ?
QStringLiteral("Change of system's default configuration: %1. Currently using %2.")
.arg(conf.name(), m_session->configuration().name())
:
QStringLiteral("Change of system's default configuration: %1. Currently using %2 (active: %3).")
.arg(conf.name(), m_session->configuration().name(), sessionsActiveConfiguration().name()));
reconnect = true;
}
if (reconnect) {
m_model->setNetworkPolicy(NETWORK_OFFLINE);
resetSession();
if (m_session->configuration().isValid()) {
m_session->open();
} else {
m_model->logTrace(0, Common::LOG_OTHER, QStringLiteral("Network Session"),
QStringLiteral("Waiting for network to become available..."));
}
}
}
示例3: settings
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()));
}
示例4: 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"));
*/
}
示例5: settings
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: settings
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()));
}
示例7: settings
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";
}
示例8: settings
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);
}
}
示例9: settings
Server::Server(QWidget *parent) :
QDialog(parent),
mTcpServer(0),
mNetworkSession(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();
}
mNetworkSession = new QNetworkSession(config, this);
connect(mNetworkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
mNetworkSession->open();
} else {
sessionOpened();
}
mIPAddressMapper = new QSignalMapper;
connect(mTcpServer, SIGNAL(newConnection()), this, SLOT(acceptClientConnection()));
connect(mIPAddressMapper, SIGNAL(mapped(QString)), this, SIGNAL(clientDisconnected(QString)));
}
示例10: init
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;
}
示例11: onNetworkConfigurationChanged
void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration &config)
{
if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) {
m_lastConfig = config;
onNetworkChange();
}
}
示例12: StartServer
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()));
}
示例13: validWlanConfiguration
/*!
Returns true if \a configuration is a valid WLAN network configuration.
False otherwise.
*/
bool ConnectionManager::validWlanConfiguration(
QNetworkConfiguration &configuration) const
{
bool valid =
#ifdef Q_OS_SYMBIAN
(configuration.isValid() &&
configuration.bearerType() == QNetworkConfiguration::BearerWLAN);
#else
(configuration.isValid() &&
(configuration.bearerType() == QNetworkConfiguration::BearerWLAN
|| configuration.type() == QNetworkConfiguration::ServiceNetwork));
#endif
if (valid) {
qDebug() << "ConnectionManager::validWlanConfiguration():"
<< configuration.name()
<< configuration.bearerTypeName()
<< configuration.bearerType()
<< configuration.type()
<< configuration.state()
<< configuration.isValid();
}
return valid;
}
示例14: onNetworkConfigurationChanged
void NetworkSession::onNetworkConfigurationChanged(const QNetworkConfiguration& config)
{
if (d.enabled && config.state() == QNetworkConfiguration::Active && d.config.state() != QNetworkConfiguration::Active) {
d.config = config;
emit connectionChanged();
}
}
示例15: 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 );
}