本文整理汇总了C++中QNetworkConfiguration::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkConfiguration::isValid方法的具体用法?C++ QNetworkConfiguration::isValid怎么用?C++ QNetworkConfiguration::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkConfiguration
的用法示例。
在下文中一共展示了QNetworkConfiguration::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: comparison
void tst_QNetworkConfiguration::comparison()
{
//test copy constructor and assignment operator
//compare invalid connection points
QNetworkConfiguration pt1;
QVERIFY(!pt1.isValid());
QVERIFY(pt1.type() == QNetworkConfiguration::Invalid);
QNetworkConfiguration pt2(pt1);
QVERIFY(pt1==pt2);
QVERIFY(!(pt1!=pt2));
QVERIFY(pt1.name() == pt2.name());
QVERIFY(pt1.isValid() == pt2.isValid());
QVERIFY(pt1.type() == pt2.type());
QVERIFY(pt1.state() == pt2.state());
QVERIFY(pt1.purpose() == pt2.purpose());
QNetworkConfiguration pt3;
pt3 = pt1;
QVERIFY(pt1==pt3);
QVERIFY(!(pt1!=pt3));
QVERIFY(pt1.name() == pt3.name());
QVERIFY(pt1.isValid() == pt3.isValid());
QVERIFY(pt1.type() == pt3.type());
QVERIFY(pt1.state() == pt3.state());
QVERIFY(pt1.purpose() == pt3.purpose());
//test case must run on machine that has valid connection points
QNetworkConfigurationManager manager;
QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations();
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations(QNetworkConfiguration::Discovered);
QVERIFY(configs.count());
QNetworkConfiguration defaultConfig = manager.defaultConfiguration();
QVERIFY(defaultConfig.isValid());
QVERIFY(defaultConfig.type() != QNetworkConfiguration::Invalid);
QVERIFY(!defaultConfig.name().isEmpty());
pt3 = defaultConfig;
QVERIFY(defaultConfig==pt3);
QVERIFY(!(defaultConfig!=pt3));
QVERIFY(defaultConfig.name() == pt3.name());
QVERIFY(defaultConfig.isValid() == pt3.isValid());
QVERIFY(defaultConfig.type() == pt3.type());
QVERIFY(defaultConfig.state() == pt3.state());
QVERIFY(defaultConfig.purpose() == pt3.purpose());
}
示例2: 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);
}
示例3: 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;
}
示例4: startSession
NetworkSessionManagerPrivate::NetworkSessionManagerPrivate(NetworkSessionManager *parent)
: q_ptr(parent),
networkSession(0),
#ifdef __ARMEL__
isSessionReady(false)
#else
isSessionReady(true)
#endif
{}
NetworkSessionManagerPrivate::~NetworkSessionManagerPrivate()
{
if (networkSession)
delete networkSession;
}
void NetworkSessionManagerPrivate::startSession()
{
Q_Q(NetworkSessionManager);
#ifndef __ARMEL__
emit q->sessionReady();
return;
#endif
if (networkSession && !isSessionReady) {
networkSession->open();
} else {
QNetworkConfigurationManager manager;
QNetworkConfiguration cfg = manager.defaultConfiguration();
if (!cfg.isValid()) {
QLatin1String msg("Network configuration manager -"
"invalid default configuration");
qWarning() << msg;
emit q->error(NetworkSessionManager::Configuration);
return;
}
if (networkSession == 0) {
networkSession = new QNetworkSession(cfg);
connect(networkSession,
SIGNAL(error(QNetworkSession::SessionError)),
SLOT(sessionErrorHandler(QNetworkSession::SessionError)));
connect(networkSession,
SIGNAL(stateChanged(QNetworkSession::State)),
SLOT(sessionStateHandler(QNetworkSession::State)));
connect(networkSession, SIGNAL(opened()), SLOT(sessionOpened()));
}
// pops up connectivity if needed
networkSession->open();
}
}
示例5: printNetworkConfigStatus
void ConnectionManagerPrivate::printNetworkConfigStatus(const QNetworkConfiguration &config) {
qDebug() << "Bearer:" << config.bearerTypeName();
qDebug() << "Roaming available:" << config.isRoamingAvailable();
qDebug() << "Valid:" << config.isValid();
qDebug() << "Name:" << config.name();
qDebug() << "Purpose:" << config.purpose();
qDebug() << "State:" << config.state();
qDebug() << "Type:" << config.type();
}
示例6: QWidget
RSSListing::RSSListing(QWidget *parent)
: QWidget(parent), currentReply(0)
{
#ifdef Q_OS_SYMBIAN
// Set Internet Access Point
QNetworkConfigurationManager manager;
const bool canStartIAP = manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces;
// Is there default access point, use it
QNetworkConfiguration cfg = manager.defaultConfiguration();
if (!cfg.isValid() || !canStartIAP) {
// Available Access Points not found
QMessageBox::warning(this, "Error", "No access point");
return;
}
m_session = new QNetworkSession(cfg);
m_session->open();
m_session->waitForOpened();
#endif
lineEdit = new QLineEdit(this);
lineEdit->setText("http://labs.qt.nokia.com/blogs/feed");
fetchButton = new QPushButton(tr("Fetch"), this);
treeWidget = new QTreeWidget(this);
connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
this, SLOT(itemActivated(QTreeWidgetItem*)));
QStringList headerLabels;
headerLabels << tr("Title") << tr("Link");
treeWidget->setHeaderLabels(headerLabels);
treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
connect(&manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(finished(QNetworkReply*)));
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
QVBoxLayout *layout = new QVBoxLayout(this);
QHBoxLayout *hboxLayout = new QHBoxLayout;
hboxLayout->addWidget(lineEdit);
hboxLayout->addWidget(fetchButton);
layout->addLayout(hboxLayout);
layout->addWidget(treeWidget);
setWindowTitle(tr("RSS listing example"));
#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
resize(640,480);
#endif
}
示例7: initConnection
void GuiBehind::initConnection()
{
// Connection
QNetworkConfigurationManager manager;
const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
QNetworkConfiguration cfg = manager.defaultConfiguration();
if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) return;
mNetworkSession = new QNetworkSession(cfg, this);
connect(mNetworkSession, SIGNAL(opened()), this, SLOT(connectOpened()));
connect(mNetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(connectError(QNetworkSession::SessionError)));
mNetworkSession->open();
}
示例8: showConfigurations
void BearerEx::showConfigurations()
{
listWidget->clear();
QListWidgetItem* listItem;
QNetworkConfiguration defaultConfig = m_NetworkConfigurationManager.defaultConfiguration();
if (defaultConfig.type() == QNetworkConfiguration::UserChoice) {
listItem = new QListWidgetItem();
QFont font = listItem->font();
font.setBold(true);
font.setUnderline(true);
listItem->setFont(font);
listItem->setText(" UserChoice");
listItem->setData(Qt::UserRole, qVariantFromValue(defaultConfig));
listWidget->addItem(listItem);
}
QList<QNetworkConfiguration> configurations = m_NetworkConfigurationManager.allConfigurations();
for (int i=0; i<configurations.count(); i++)
{
listItem = new QListWidgetItem();
QString text;
if (configurations[i].type() == QNetworkConfiguration::InternetAccessPoint) {
text.append("(IAP,");
} else if (configurations[i].type() == QNetworkConfiguration::ServiceNetwork) {
text.append("(SNAP,");
}
if ((configurations[i].state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
text.append("Act) ");
} else if ((configurations[i].state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
text.append("Disc) ");
} else {
text.append("Def) ");
}
text.append(configurations[i].name());
if (defaultConfig.isValid() && defaultConfig == configurations[i]) {
QFont font = listItem->font();
font.setBold(true);
font.setUnderline(true);
listItem->setFont(font);
}
listItem->setText(text);
listItem->setData(Qt::UserRole, qVariantFromValue(configurations[i]));
listWidget->addItem(listItem);
}
}
示例9: configurationAdded
void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent)
{
if (!config.isValid())
return;
QTreeWidgetItem *item = new QTreeWidgetItem;
updateItem(item, config);
if (parent)
parent->addChild(item);
else
treeWidget->addTopLevelItem(item);
if (config.type() == QNetworkConfiguration::ServiceNetwork) {
foreach (const QNetworkConfiguration &child, config.children())
configurationAdded(child, item);
}
示例10: openNetworkSession
void ServiceDiscovery::openNetworkSession()
{
DEBUG_TAG(3, "SD", "trying to open network session");
// use the default network configuration and make sure that the link is open
QList<QNetworkConfiguration> availableConfigs;
QNetworkConfiguration defaultConfig = m_networkConfigManager->defaultConfiguration();
if (defaultConfig.isValid()) {
availableConfigs.append(defaultConfig);
}
availableConfigs.append(m_networkConfigManager->allConfigurations(QNetworkConfiguration::Discovered));
DEBUG_TAG(2, "SD", "number of configs: " << availableConfigs.size());
for (const QNetworkConfiguration &config: availableConfigs)
{
if (networkConfigIsQualified(config))
{
DEBUG_TAG(2, "SD", "network config: " << config.bearerTypeName() << config.bearerTypeFamily() << config.name());
if (!m_networkSession.isNull())
{
m_networkSession->deleteLater();
}
m_networkSession = new QNetworkSession(config, this);
connect(m_networkSession, &QNetworkSession::opened,
this, &ServiceDiscovery::networkSessionOpened);
connect(m_networkSession, &QNetworkSession::closed,
this, &ServiceDiscovery::networkSessionClosed);
connect(m_networkSession, static_cast<void (QNetworkSession::*)(QNetworkSession::SessionError)>(&QNetworkSession::error),
this, &ServiceDiscovery::networkSessionError);
m_networkSession->open();
return;
}
else
{
DEBUG_TAG(2, "SD", "unsupported network config: " << config.bearerTypeName() << config.bearerTypeFamily() << config.name());
}
}
}
示例11: networkAccessible
void tst_QNetworkAccessManager::networkAccessible()
{
QNetworkAccessManager manager;
qRegisterMetaType<QNetworkAccessManager::NetworkAccessibility>("QNetworkAccessManager::NetworkAccessibility");
QSignalSpy spy(&manager,
SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::NotAccessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::UnknownAccessibility);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
QNetworkConfigurationManager configManager;
QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
if (defaultConfig.isValid()) {
manager.setConfiguration(defaultConfig);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
QNetworkAccessManager::Accessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
QCOMPARE(spy.count(), 1);
QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
QNetworkAccessManager::NotAccessible);
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
}
}
示例12: invalidPoint
void tst_QNetworkConfiguration::invalidPoint()
{
QNetworkConfiguration pt;
QVERIFY(pt.name().isEmpty());
QVERIFY(!pt.isValid());
QVERIFY(pt.type() == QNetworkConfiguration::Invalid);
QVERIFY(!(pt.state() & QNetworkConfiguration::Defined));
QVERIFY(!(pt.state() & QNetworkConfiguration::Discovered));
QVERIFY(!(pt.state() & QNetworkConfiguration::Active));
QVERIFY(!pt.isRoamingAvailable());
QNetworkConfiguration pt2(pt);
QVERIFY(pt2.name().isEmpty());
QVERIFY(!pt2.isValid());
QVERIFY(pt2.type() == QNetworkConfiguration::Invalid);
QVERIFY(!(pt2.state() & QNetworkConfiguration::Defined));
QVERIFY(!(pt2.state() & QNetworkConfiguration::Discovered));
QVERIFY(!(pt2.state() & QNetworkConfiguration::Active));
QVERIFY(!pt2.isRoamingAvailable());
}
示例13: getHostAddress
// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QNetworkConfiguration &in_network_config)
{
if (in_network_config.isValid() == false) return QHostAddress();
qDebug() << "NetworkTools::getHostAddress - configuration bearer type:" << in_network_config.bearerTypeName();
QNetworkSession nws(in_network_config);
if (nws.state() == QNetworkSession::Invalid || nws.state() == QNetworkSession::NotAvailable) return QHostAddress();
qDebug() << "NetworkTools::getHostAddress - session state:" << nws.state();
QNetworkInterface nwi = nws.interface();
if (nwi.isValid() == false) return QHostAddress();
if (nwi.addressEntries().isEmpty()) return QHostAddress();
foreach(QNetworkAddressEntry temp, nwi.addressEntries())
qDebug() << "NetworkTools::getHostAddress - session addr entry:" << temp.ip().toString();
QNetworkAddressEntry nwae = nwi.addressEntries().first();
QHostAddress host_address = nwae.ip();
return host_address;
}
示例14: main
int main(int argc, char**argv)
{
QCoreApplication app(argc, argv);
#ifdef Q_OS_SYMBIAN
QNetworkConfigurationManager configurationManager;
QNetworkConfiguration configuration = configurationManager.defaultConfiguration();
if (!configuration.isValid()) {
qDebug() << "Got an invalid session configuration";
exit(1);
}
qDebug() << "Opening session...";
QNetworkSession *session = new QNetworkSession(configuration);
// Does not work:
// session->open();
// session->waitForOpened();
// works:
QEventLoop loop;
QObject::connect(session, SIGNAL(opened()), &loop, SLOT(quit()), Qt::QueuedConnection);
QMetaObject::invokeMethod(session, "open", Qt::QueuedConnection);
loop.exec();
if (session->isOpen()) {
qDebug() << "session opened";
} else {
qDebug() << "session could not be opened -" << session->errorString();
exit(1);
}
#endif
// create it
QAbstractSocketEngine *socketEngine =
QAbstractSocketEngine::createSocketEngine(QAbstractSocket::TcpSocket, QNetworkProxy(QNetworkProxy::NoProxy), 0);
if (!socketEngine) {
qDebug() << "could not create engine";
exit(1);
}
// initialize it
bool initialized = socketEngine->initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol);
if (!initialized) {
qDebug() << "not able to initialize engine";
exit(1);
}
// wait for connected
int r = socketEngine->connectToHost(QHostAddress("74.125.77.99"), 80); // google
bool readyToRead = false;
bool readyToWrite = false;
socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, true, 10*1000);
if (r <= 0) //timeout or error
exit(1);
if (readyToWrite) {
// write the request
QByteArray request("GET /robots.txt HTTP/1.0\r\n\r\n");
int ret = socketEngine->write(request.constData(), request.length());
if (ret == request.length()) {
// read the response in a loop
do {
bool waitReadResult = socketEngine->waitForRead(10*1000);
int available = socketEngine->bytesAvailable();
if (waitReadResult == true && available == 0) {
// disconnected
exit(0);
}
bzero(buf, bufsize);
ret = socketEngine->read(buf, available);
if (ret > 0) {
#ifdef Q_OS_SYMBIAN
qDebug() << buf; //printf goes only to screen, this goes to remote debug channel
#else
printf("%s", buf);
#endif
} else {
// some failure when reading
exit(1);
}
} while (1);
} else {
qDebug() << "failed writing";
}
} else {
qDebug() << "failed connecting";
}
delete socketEngine;
}
示例15: printConfigurationDetails
void printConfigurationDetails(const QNetworkConfiguration& p)
{
qDebug() << p.name() <<": isvalid->" <<p.isValid() << " type->"<< p.type() <<
" roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() <<
" purpose->" << p.purpose() << " state->" << p.state();
}