コード例 #1
0
ファイル: server.cpp プロジェクト: bukmare/ESP_CStation
void Server::StartServer()
{
    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(sessionOpened()));

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

    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(recieveConnection()));
}
コード例 #2
0
ファイル: server.cpp プロジェクト: IlyaNikiforov/tools
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)));
}
コード例 #3
0
ファイル: server.cpp プロジェクト: fangbinbin/myRep
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
0
ファイル: server.cpp プロジェクト: emericg/Metabot
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
0
ファイル: tcpechoserver.cpp プロジェクト: wickwire/nfrider
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);
    }
}
コード例 #6
0
Server::Server(QWidget *parent) :
    QDialog(parent), tcpServer(0), clientSocket(0), networkSession(0),
    blockSize(0)
{
    serverStatusLabel = new QLabel(tr("Status"));
    messageLabel = new QLabel(tr("Message:"));
    quitButton = new QPushButton(tr("Quit"));
    quitButton->setAutoDefault(false);
    sendMessageButton = new QPushButton(tr("Send Message"));

    chatBox = new QTextEdit;
    chatBox->setReadOnly(true);

    messageLineEdit = new QLineEdit;
    messageLineEdit->setEnabled(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()));

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


    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(serverStatusLabel, 0, 0);
    mainLayout->addWidget(messageLabel, 2, 0);
    mainLayout->addWidget(messageLineEdit, 3, 0);
    mainLayout->addWidget(sendMessageButton, 4, 0);
    mainLayout->addWidget(chatBox, 5, 0);
    mainLayout->addWidget(quitButton, 6, 0, 1, 2);
    setLayout(mainLayout);


    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(sendMessageButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(clientProcessing()));

    setWindowTitle("Server");
}
コード例 #7
0
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::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()));

        ///statusLabel->setText(tr("Opening network session."));
        std::cout << "Opening network session." << std::endl;

        networkSession->open();
    } else {
        sessionOpened();
    }

        fortunes << tr("bla bla bue ee ee e e.")
                 << tr("You've got to think about tomorrow.")
                 << tr("You wi Q_OBJECTll 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.");

        ///connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));

//        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"));
}
コード例 #8
0
ファイル: server.cpp プロジェクト: jadow/busguide3-3
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::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()));

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

        fortunes << tr("all in on this");


        connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));

        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"));
}
コード例 #9
0
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;
}
コード例 #10
0
ファイル: pru.cpp プロジェクト: HebaKhaled/models
pru::pru(QWidget *parent) : QDialog(parent), tcpServer(0), networkSession(0) {
  // background image
  setStyleSheet("background-image: url(:/images/pru.png);");
  // readouts
  arm.setStyleSheet("background:transparent; font:bold 28px; color: darkblue;");
  arm.setMinimumSize(36, 36);
  SpO2.setStyleSheet("background:transparent; font:bold 28px; color: darkblue;");
  SpO2.setMinimumSize(36, 36);
  HR.setStyleSheet("background:transparent; font:bold 28px; color: darkblue;");
  HR.setMinimumSize(36, 36);
  systolic.setStyleSheet("background:transparent; font:bold 16px; color: darkblue;");
  systolic.setMinimumSize(36, 36);
  respiration.setStyleSheet("background:transparent; font:bold 28px; color: darkblue;");
  respiration.setMinimumSize(36, 36);
  etCO2.setStyleSheet("background:transparent; font:bold 28px; color: darkblue;");
  etCO2.setMinimumSize(36, 36);
  // button images
  QPixmap stopPixmap(":/images/end_case.png");
  QPixmap stopPressedPixmap(":/images/end_case_pressed.png");
  // icons
  stopIcon.addPixmap(stopPixmap); stopPressedIcon.addPixmap(stopPressedPixmap);
  // button definitions
  stopButton.setIcon(stopIcon);
  stopButton.setIconSize(stopPixmap.rect().size());
  stopButton.setStyleSheet("border:none;");

  sessionOpened();

  // connect starting socket communication
  connect(tcpServer, SIGNAL(newConnection()), this, SLOT(initConnect()));

  layout.setColumnMinimumWidth(0,420);
  layout.addWidget(&respiration, 0, 2, Qt::AlignHCenter | Qt::AlignVCenter);
  layout.addWidget(&etCO2, 0, 4, Qt::AlignHCenter | Qt::AlignVCenter);
  layout.addWidget(&SpO2, 1, 3, Qt::AlignHCenter | Qt::AlignVCenter);
  layout.setVerticalSpacing(60);
  layout.addWidget(&HR, 3, 2, Qt::AlignHCenter | Qt::AlignVCenter);
  layout.addWidget(&systolic, 3, 4, Qt::AlignLeft | Qt::AlignLeft);
  layout.addWidget(&arm, 4, 3, Qt::AlignHCenter | Qt::AlignVCenter);
  layout.setRowMinimumHeight(5,76);
  layout.addWidget(&stopButton, 6, 4, Qt::AlignLeft | Qt::AlignLeft);
  layout.setColumnMinimumWidth(5,232);

  QVBoxLayout *mainLayout = new QVBoxLayout;
  mainLayout->addSpacing(48);
  mainLayout->addLayout(&layout);
  mainLayout->addSpacing(28);
  setLayout(mainLayout);

  respiration.setText( "" );
  etCO2.setText( "" );
  SpO2.setText( "" );
  HR.setText( "" );
  systolic.setText( "" );
  arm.setText( "" );
  setWindowTitle(tr("PRU"));
}
コード例 #11
0
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();
    }
}
コード例 #12
0
ファイル: mapzoom.cpp プロジェクト: AlexSoehn/qt-base-deb
MapZoom::MapZoom()
    : QMainWindow(0)
{
    map = new LightMaps(this);
    setCentralWidget(map);
    map->setFocus();

    QAction *osloAction = new QAction(tr("&Oslo"), this);
    QAction *berlinAction = new QAction(tr("&Berlin"), this);
    QAction *jakartaAction = new QAction(tr("&Jakarta"), this);
    QAction *nightModeAction = new QAction(tr("Night Mode"), this);
    nightModeAction->setCheckable(true);
    nightModeAction->setChecked(false);
    QAction *osmAction = new QAction(tr("About OpenStreetMap"), this);
    connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo()));
    connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin()));
    connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta()));
    connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode()));
    connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm()));

    QMenu *menu = menuBar()->addMenu(tr("&Options"));
    menu->addAction(osloAction);
    menu->addAction(berlinAction);
    menu->addAction(jakartaAction);
    menu->addSeparator();
    menu->addAction(nightModeAction);
    menu->addAction(osmAction);

    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 {
        networkSession = 0;
    }

    setWindowTitle(tr("Light Maps"));
}
コード例 #13
0
ファイル: server.cpp プロジェクト: artbez/origin
Server::Server(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Server),
    tcpServer(0),
    clientSocket(0),
    networkSession(0),
    blockSize(0)
{
    ui->setupUi(this);
    statusLabel = ui->statusLabel;
    connectionLabel = ui->connectionLabel;
    okButton = ui->okButton;
    okButton->setEnabled(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()));

        statusLabel->setText("Открытие сессии.");
        networkSession->open();
    }
    else
        sessionOpened();

    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));

    setWindowTitle("Настройки сервера");
}
コード例 #14
0
ファイル: server.cpp プロジェクト: anates/TCP-controller
Server::Server(QString ipAddr, quint32 port, QString purpose)
:  tcpServer(0), networkSession(0)
{
    Server::clientConnection = NULL;
    Server::purpose = purpose;
    Server::port = port;
    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()));

        //statusLabel->setText(tr("Opening network session."));
        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.");
        //connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
        connect(tcpServer, SIGNAL(newConnection()), this, SLOT(openNewConnection()));
        //connect(tcpServer, &QTcpServer::newConnection, this, &Server::openNewConnection);
}
コード例 #15
0
  ctkXnatSession *XnatSessionTracker::AddingService(const ServiceReferenceType &reference)
  {
    ctkXnatSession *session = Superclass::AddingService(reference);
    if (session->isOpen())
    {
      emit Opened(session);
    }
    connect(session, SIGNAL(sessionOpened()), this, SLOT(SessionOpened()));
    connect(session, SIGNAL(sessionAboutToBeClosed()), this, SLOT(SessionAboutToBeClosed()));

    return session;
  }
コード例 #16
0
ファイル: HelperApp.cpp プロジェクト: Acidburn0zzz/sddm-1
    void HelperApp::doAuth() {
        SafeDataStream str(m_socket);
        str << Msg::HELLO << m_id;
        str.send();
        if (str.status() != QDataStream::Ok)
            qCritical() << "Couldn't write initial message:" << str.status();

        if (!m_backend->start(m_user)) {
            authenticated(QString(""));
            exit(Auth::HELPER_AUTH_ERROR);
            return;
        }

        if (!m_backend->authenticate()) {
            authenticated(QString(""));
            exit(Auth::HELPER_AUTH_ERROR);
            return;
        }

        m_user = m_backend->userName();
        QProcessEnvironment env = authenticated(m_user);

        if (!m_session->path().isEmpty()) {
            env.insert(m_session->processEnvironment());
            m_session->setProcessEnvironment(env);

            if (!m_backend->openSession()) {
                sessionOpened(false);
                exit(Auth::HELPER_SESSION_ERROR);
                return;
            }

            sessionOpened(true);
        }
        else
            exit(Auth::HELPER_SUCCESS);
        return;
    }
コード例 #17
0
TCP_Song::TCP_Song(void)
{
    // find out name of this machine
    QString name = QHostInfo::localHostName();
    if (!name.isEmpty())
    {
        qDebug() << name << endl;
    }
     // find out IP addresses of this machine
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // add non-localhost addresses
    for (int i = 0; i < ipAddressesList.size(); ++i)
    {
        if (!ipAddressesList.at(i).isLoopback())
                  qDebug() << ipAddressesList.at(i).toString() << endl;
    }

    tcpSocket = new QTcpSocket(this);



    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readSongs()));
    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();
    }

}
コード例 #18
0
ファイル: moc_server.cpp プロジェクト: ngocthanhtnt/ledshow
int Server::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            sessionOpened();
            break;
        case 1:
            sendFortune();
            break;
        default:
            ;
        }
        _id -= 2;
    }
    return _id;
}
コード例 #19
0
Client::Client(QWidget *parent) : QWidget(parent), networkSession(0)
{
    _config = new Config();
    state = 1;
    setWindowTitle(tr("RORI"));
    _connectionInt = new ConnectionInterface(_config, this);
    _connectedInt = new ConnectedClass(_config, this);
    configSsl();

    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()));

        _connectionInt->setStatus(tr("Opening network session."));
        networkSession->open();
    }

    connect(this, SIGNAL(dataFromClient(QSslSocket*,QString)), this, SLOT(parseJSON(QSslSocket*,QString)));
    connect(_connectionInt, SIGNAL(connectBtnClicked()), this, SLOT(connectToEntry()));
    connect(_connectedInt, SIGNAL(sendMessage(QString)), this, SLOT(sendMessage(QString)));

    _connectionInt->setFixedSize(QApplication::desktop()->width()/3, QApplication::desktop()->height()-50);
    _connectedInt->setFixedSize(QApplication::desktop()->width()/3, QApplication::desktop()->height()-50);
    setFixedSize(QApplication::desktop()->width()/3, QApplication::desktop()->height()-50);
    show();
}
コード例 #20
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    hotelServer(Q_NULLPTR),
    networkSession(0),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //sets manager incase something changes
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));

        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();
        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, &MainWindow::sessionOpened);
        networkSession->open();

    }

    else {//opens session straight away
            sessionOpened();}

    hotelInfo =tr("Hotel Name: Hampton Inn\n"
                      "Number of available rooms: 50\n"
                      "Number of floors: 10\n"
                      "Number of unavailable rooms: 5");

    //hotelInfo set for mock purposes
    connect(ui->quitButton, &QAbstractButton::clicked, this, &QWidget::close);
    connect(hotelServer, &QTcpServer::newConnection, this, &MainWindow::sendHotelInfo);

    setWindowTitle("Hotel Server");
}
コード例 #21
0
ファイル: server.cpp プロジェクト: bukmare/ESP_CStation
void Server::Reset()
{
    emit write_message(tr("Reseting server."));

    if (!sockets->isEmpty()) {
        QMap<quint32, QTcpSocket *>::const_iterator i = sockets->constBegin();
        while (i != sockets->constEnd()) {
            QTcpSocket* tcpSocket = i.value();
            if (tcpSocket) {
                emit write_message(tr("Sending reset signal to %1.").arg(tcpSocket->peerAddress().toString()));
                tcpSocket->write("SERV_RST=1\r\n\r\n");
                tcpSocket->flush();
            }
            ++i;
        }
        sockets->clear();
    }
    if (tcpServer) {
        tcpServer->close();
    }
    sessionOpened();
}
コード例 #22
0
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
  Server::Server(QWidget *parent)
    :   QDialog(parent), m_network_session(0)
  {
    m_status_label = new QLabel;
    m_quit_button = new QPushButton(tr("Quit"));
    m_quit_button->setAutoDefault(false);

    //protocol
    m_protocol = new Protocol(PROTOCOL_VERSION);
    
    m_block_size = 0;
  
    m_log_label = new QTextEdit;
    m_log_label->setReadOnly(true);
    m_log_label->setStyleSheet("border: 2px solid black; color: black; background-color: white;");
    m_log_label->setFixedSize(500,300);
    m_log_label->setAlignment(Qt::AlignTop | Qt::AlignLeft);

    m_online_users_label = new QTextEdit;
    m_online_users_label->setReadOnly(true);
    m_online_users_label->setStyleSheet("border: 2px solid black; color: black; background-color: white;");
    m_online_users_label->setFixedSize(300,100);
    m_online_users_label->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
  
    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_network_session = new QNetworkSession(config, this);
      connect(m_network_session, SIGNAL(opened()), this, SLOT(sessionOpened()));

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

    //object connections
    connect(m_quit_button, SIGNAL(clicked()), this, SLOT(close()));
    connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(acceptUser()));

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

    m_main_layout = new QVBoxLayout;
    m_main_layout->addWidget(m_status_label);
    m_main_layout->addWidget(m_log_label);
    m_main_layout->addWidget(new QLabel("Currently online users:"));
    m_main_layout->addWidget(m_online_users_label);
    m_main_layout->addLayout(buttonLayout);
    setLayout(m_main_layout);

    setWindowTitle(tr("Messenger Server"));
    this->layout()->setSizeConstraint( QLayout::SetFixedSize );
  }
コード例 #23
0
int TCST::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            button1Clicked();
            break;
        case 1:
            registerButtonClicked();
            break;
        case 2:
            browseForLocation();
            break;
        case 3:
            browseForFile();
            break;
        case 4:
            connectToServer();
            break;
        case 5:
            sendRequest();
            break;
        case 6:
            sendFile();
            break;
        case 7:
            updateLabels();
            break;
        case 8:
            confirmFile();
            break;
        case 9:
            displayError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1])));
            break;
        case 10:
            connectionClosedByServer();
            break;
        case 11:
            sessionOpened();
            break;
        case 12:
            reloadMenu();
            break;
        case 13:
            registerWithServer();
            break;
        case 14:
            printStatus();
            break;
        case 15:
            reconnect();
            break;
        default:
            ;
        }
        _id -= 16;
    }
    return _id;
}
コード例 #24
0
Client::Client(QWidget *parent) : QMainWindow(parent), networkSession(0) {
    sysInfo = new QSystemDeviceInfo(this);
    QGeoPositionInfo::QGeoPositionInfo(info);

    QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
    if(source){
         connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positonUpdated(QGeoPositionInfo)));
         source->requestUpdate();
     }

    hostLabel = new QLabel(tr("&Server name:"));
    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
            ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            //#############KOSTIL'##################
            ipAddress = "91.221.60.166";
            break;
        }
    }
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    hostLineEdit = new QLineEdit(ipAddress);
    hostLabel->setBuddy(hostLineEdit);

    statusLabel = new QLabel(tr(""));

    alarmTypeUnus = new QPushButton(tr("Fire"));
    alarmTypeDuo = new QPushButton(tr("Pain"));
    alarmTypeTres = new QPushButton(tr("Breakin"));

    quitButton = new QPushButton(tr("Quit"));
    sendButton = new QPushButton(tr("Send datastring"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);

    tcpSocket = new QTcpSocket(this);

    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(alarmTypeUnus, SIGNAL(clicked()), this, SLOT(pressedUnus()));
    connect(alarmTypeDuo, SIGNAL(clicked()), this, SLOT(pressedDuo()));
    connect(alarmTypeTres, SIGNAL(clicked()), this, SLOT(pressedTres()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(hostLabel, 0, 0);
    mainLayout->addWidget(hostLineEdit, 0, 1);
    mainLayout->addWidget(alarmTypeUnus, 3, 0);
    mainLayout->addWidget(alarmTypeDuo, 3, 1);
    mainLayout->addWidget(alarmTypeTres, 3, 2);
    mainLayout->addWidget(buttonBox, 4, 0);
    setLayout(mainLayout);

    setWindowTitle(tr("Alarm Client"));
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        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();

    }
}
コード例 #25
0
ファイル: client.cpp プロジェクト: amejiarosario/TcpServer
Client::Client(QWidget *parent)
:   QDialog(parent), networkSession(0)
{
    hostLabel = new QLabel(tr("&Server name:"));
    portLabel = new QLabel(tr("S&erver port:"));

    // find out which IP to connect to
    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i)
    {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address())
        {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }

    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    hostLineEdit = new QLineEdit(ipAddress);
    portLineEdit = new QLineEdit;
    portLineEdit->setText("27015"); // hack default
    portLineEdit->setValidator(new QIntValidator(1, 65535, this));

    hostLabel->setBuddy(hostLineEdit);
    portLabel->setBuddy(portLineEdit);

    statusLabel = new QLabel(tr("This examples requires that you run the Fortune Server example as well."));

    getFortuneButton = new QPushButton(tr("Get Fortune"));
    getFortuneButton->setDefault(true);
    getFortuneButton->setEnabled(false);

    testButton = new QPushButton(tr("Test"));
    testButton->setDefault(false);
    testButton->setEnabled(true);

    quitButton = new QPushButton(tr("Quit"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(testButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);

    tcpSocket = new QTcpSocket(this);

    connect(hostLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableGetFortuneButton()));
    connect(portLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableGetFortuneButton()));
    connect(getFortuneButton, SIGNAL(clicked()), this, SLOT(requestNewFortune()));
    connect(testButton, SIGNAL(clicked()), this, SLOT(test()));
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(hostLabel, 0, 0);
    mainLayout->addWidget(hostLineEdit, 0, 1);
    mainLayout->addWidget(portLabel, 1, 0);
    mainLayout->addWidget(portLineEdit, 1, 1);
    mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
    mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
    setLayout(mainLayout);

    setWindowTitle(tr("Fortune Client"));
    portLineEdit->setFocus();

    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();
        }

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

        getFortuneButton->setEnabled(false);
        statusLabel->setText(tr("Opening network session."));
        networkSession->open();
    }
}
コード例 #26
0
ファイル: server.cpp プロジェクト: ladygo/Fortune
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::NetworkSessionRequired) {
        // 保读取保存的网络配置
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetWork"));
        // 如果不存在返回一个空值
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();


        // 如果保存的网络配置不是当前发现的使用系统默认的
        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();
        qDebug() << "arrived here!";

    } else {
        qDebug() << "arrived here ......!";
        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.");

    // 链接quitButton
    connect(quitButton, SIGNAL(clicked(bool)), this, SLOT(close()));
    //绑定新链接信号到sentFortune槽,如果有数据 就调用函数处理
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));


    // 布局设置
    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 Sever"));
}
コード例 #27
0
ファイル: server.cpp プロジェクト: coshaugh/CS441
Server::Server(QWidget *parent)
    : QDialog(parent)
    , statusLabel(new QLabel)
    , tcpServer(Q_NULLPTR)
    , networkSession(0)
    , blockSize(0)
    , linkCombo(new QComboBox)
{
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);

    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, &Server::sessionOpened);

        statusLabel->setText(tr("Opening network session."));
        networkSession->open();
    } else {
        sessionOpened();
    }
//----------------------------------------------------------------------------------------------------------------
    QLabel *youTubeLinksLabel = new QLabel(tr("youTubeLinksLabel:"));
    youTubeLinksLabel->setBuddy(linkCombo);

    QPushButton *quitButton = new QPushButton(tr("Quit"));
    quitButton->setAutoDefault(false);

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(quitButton);
    buttonLayout->addStretch(1);
//----------------------------------------------------------------------------------------------------------------
    connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
    connect(tcpServer, &QTcpServer::newConnection, this, &Server::storeLink);
//----------------------------------------------------------------------------------------------------------------

    QVBoxLayout *mainLayout = Q_NULLPTR;
    if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
        QVBoxLayout *outerVerticalLayout = new QVBoxLayout(this);
        outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
        QHBoxLayout *outerHorizontalLayout = new QHBoxLayout;
        outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
        QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName());
        mainLayout = new QVBoxLayout(groupBox);
        outerHorizontalLayout->addWidget(groupBox);
        outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
        outerVerticalLayout->addLayout(outerHorizontalLayout);
        outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
    } else {
        mainLayout = new QVBoxLayout(this);
    }

    mainLayout->addWidget(statusLabel);
    mainLayout->addLayout(buttonLayout);

    mainLayout->addWidget(youTubeLinksLabel);
    mainLayout->addWidget(linkCombo);

    setWindowTitle(QGuiApplication::applicationDisplayName());
}
コード例 #28
0
ファイル: client.cpp プロジェクト: edwardtoday/qt-tcpclient
//! [0]
Client::Client(QWidget *parent)
:   QDialog(parent), networkSession(0)
{
//! [0]
    hostLabel = new QLabel(tr("&Server name:"));
    portLabel = new QLabel(tr("S&erver port:"));

    hostCombo = new QComboBox;
    hostCombo->setEditable(true);
    // find out name of this machine
    QString name = QHostInfo::localHostName();
    if (!name.isEmpty()) {
        hostCombo->addItem(name);
        QString domain = QHostInfo::localDomainName();
        if (!domain.isEmpty())
            hostCombo->addItem(name + QChar('.') + domain);
    }
    if (name != QString("localhost"))
        hostCombo->addItem(QString("localhost"));
    // find out IP addresses of this machine
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // add non-localhost addresses
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (!ipAddressesList.at(i).isLoopback())
            hostCombo->addItem(ipAddressesList.at(i).toString());
    }
    // add localhost addresses
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i).isLoopback())
            hostCombo->addItem(ipAddressesList.at(i).toString());
    }

    portLineEdit = new QLineEdit;
    portLineEdit->setValidator(new QIntValidator(1, 65535, this));

    hostLabel->setBuddy(hostCombo);
    portLabel->setBuddy(portLineEdit);

    statusLabel = new QLabel(tr("This examples requires that you run the "
                                "Qt TCP Server as well."));

    getFortuneButton = new QPushButton(tr("Get Data"));
    getFortuneButton->setDefault(true);
    getFortuneButton->setEnabled(false);

    quitButton = new QPushButton(tr("Quit"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);

//! [1]
    tcpSocket = new QTcpSocket(this);
//! [1]

    connect(hostCombo, SIGNAL(editTextChanged(QString)),
            this, SLOT(enableGetFortuneButton()));
    connect(portLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(enableGetFortuneButton()));
    connect(getFortuneButton, SIGNAL(clicked()),
            this, SLOT(requestNewFortune()));
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
//! [2] //! [3]
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
//! [2] //! [4]
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
//! [3]
            this, SLOT(displayError(QAbstractSocket::SocketError)));
//! [4]

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(hostLabel, 0, 0);
    mainLayout->addWidget(hostCombo, 0, 1);
    mainLayout->addWidget(portLabel, 1, 0);
    mainLayout->addWidget(portLineEdit, 1, 1);
    mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
    mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
    setLayout(mainLayout);

    setWindowTitle(tr("Qt TCP Client"));
    portLineEdit->setFocus();

    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()));

        getFortuneButton->setEnabled(false);
        statusLabel->setText(tr("Opening network session."));
        networkSession->open();
    }
//! [5]
}
コード例 #29
0
Client::Client(QWidget *parent)
    : QDialog(parent), networkSession(0)
{
	 // find out which IP to connect to
	QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
	// use the first non-localhost IPv4 address
	for (int i = 0; i < ipAddressesList.size(); ++i) {
		if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
			ipAddressesList.at(i).toIPv4Address()) {
			ipAddress = ipAddressesList.at(i).toString();
			break;
		}
	}
	// if we did not find one, use IPv4 localhost
	if (ipAddress.isEmpty())
		ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

	userLabel = new QLabel("Username: "******"Password: "******"Register");
	loginButton = new QPushButton("Login");
	cancelButton = new QPushButton("Cancel");

	buttonBox = new QDialogButtonBox();
	buttonBox->addButton(registerButton, QDialogButtonBox::ActionRole);
	buttonBox->addButton(loginButton, QDialogButtonBox::ActionRole);
	buttonBox->addButton(cancelButton, QDialogButtonBox::RejectRole);

	mainLayout = new QGridLayout;
	mainLayout->addWidget(userLabel, 0, 0, 1, 2);
	mainLayout->addWidget(userLineEdit, 1, 0, 1, 5);
	mainLayout->addWidget(passLabel, 2, 0, 1, 2);
	mainLayout->addWidget(passLineEdit, 3, 0, 1, 5);
	mainLayout->addWidget(statusLabel, 4, 0, 3, 4);
	mainLayout->addWidget(buttonBox, 7, 1, 1, 2);

	setLayout(mainLayout);

	tcpSocket = new QTcpSocket(this);

	connect(registerButton, SIGNAL(clicked()), this, SLOT(registerWithServer()));
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
	connect(loginButton, SIGNAL(clicked()), this, SLOT(requestNewConnection()));
	connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendLoginInfo()));
	connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(updateLabels()));
	//connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(connectionClosedByServer()));

	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();
		}

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

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

}
コード例 #30
0
void CReporterNwSessionMgr::emitSessionOpened()
{
    networkSessionOpened = true;
    emit sessionOpened();
}