Exemplo n.º 1
0
void MuxerChannel::setMuxer(DeviceMuxer* mux)
{
    if (mux == _muxer)
        return;
    // Disconnect signals from old muxer
    if (_muxer) {
        disconnect(_muxer, SIGNAL(readyRead(channel_t)),
                   this, SLOT(handleReadyRead(channel_t)));
        disconnect(_muxer, SIGNAL(deviceChanged(QIODevice*, QIODevice*)),
                   this, SLOT(handleDeviceChanged(QIODevice*, QIODevice*)));
        if (_muxer->device())
			disconnect(_muxer->device(), SIGNAL(readChannelFinished()),
					   this, SIGNAL(readChannelFinished()));
    }

    _muxer = mux;

    // Connect signals to new muxer
    if (_muxer) {
        connect(_muxer, SIGNAL(readyRead(channel_t)),
                this, SLOT(handleReadyRead(channel_t)));
        connect(_muxer, SIGNAL(deviceChanged(QIODevice*, QIODevice*)),
                this, SLOT(handleDeviceChanged(QIODevice*, QIODevice*)));
        if (_muxer->device())
			connect(_muxer->device(), SIGNAL(readChannelFinished()),
					this, SIGNAL(readChannelFinished()));
    }
}
void DownloadManager::handleGetFinished(QNetworkReply *reply)
{
    if(reply->error() == QNetworkReply::NoError)
    {
        QUrl redirectionUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toUInt();

        qDebug() << "Handling get request with response code" << responseCode;

        switch (responseCode) {
        case RESPONSE_FOUND:
            redirectionUrl = reply->header(QNetworkRequest::LocationHeader).toUrl();
        case RESPONSE_REDIRECT:
            if (redirectionUrl.isValid()) {
                qDebug() << reply->url() << "redirected to" << redirectionUrl;

                /* Make sure we don't send out unnecessary get requests */
                if (latestReply && latestReply->url() == redirectionUrl)
                    break;

                /* Prepare for download */
                get(redirectionUrl);
                connect(latestReply, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
            }
            else {
                qDebug() << "Redirected but no redirection url?!";
            }
            break;

        case RESPONSE_OK:
            qDebug() << "Downloaded" << reply->header(QNetworkRequest::ContentLengthHeader).toLongLong() << "bytes from" << reply->url().toString();
            emit downloadComplete(reply->readAll());
            break;

        case RESPONSE_PARTIAL:
            handleReadyRead();
            break;

        default:
            qDebug() << "Unhandled reply:" << responseCode;
            foreach (const QByteArray& header, reply->rawHeaderList()) {
                qDebug() << header << reply->rawHeader(header);
            }
            break;
        }
    }
Exemplo n.º 3
0
void Connector::stopRead()
{
    qDebug("stop Read");
    disconnect(this, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
    disconnect(this, SIGNAL(readAllData()), this, SLOT(handleReadData()));
    //清空
    ba.clear();
    clear();
}
Exemplo n.º 4
0
SerialPortReader::SerialPortReader()
{

    this->serialPort.setBaudRate(QSerialPort::Baud9600);

    checkSerialPortAvailable();

    connect(&this->serialPort,SIGNAL(readyRead()),this,SLOT(handleReadyRead()));
    connect(&serialPort, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));
}
Exemplo n.º 5
0
void FtpClient::init()
{
    qDebug() << "FtpClient:: " << port << " Init";
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    qDebug() << "FtpClient:: " << port << " Init connect";
    // from abtractsocket
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(handleError(QAbstractSocket::SocketError)));
    connect(tcpSocket, SIGNAL(connected()), this, SLOT(handleConnected()));
    connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(handleDisconnected()));
    connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(handleHostFound()));
    connect(tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)), this, SLOT(handleProxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)));
    connect(tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleStateChanged(QAbstractSocket::SocketState)));
    // from QIODevice
    connect(tcpSocket, SIGNAL(aboutToClose()), this, SLOT(handleAboutToClose()));
    connect(tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(handleBytesWritten(qint64)));
    connect(tcpSocket, SIGNAL(readChannelFinished()), this, SLOT(handleReadChannelFinished()));
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));


    qDebug() << "FtpClient:: " << port << " Init NetworkConfigurationManager manager";
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        qDebug() << "FtpClient::Init QNetworkConfigurationManager::NetworkSessionRequired";
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String(SETTING_STR));
        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();
        }

        qDebug() << "FtpClient:: " << port << " Init new QNetworkSession(config, this)";
        networkSession = new QNetworkSession(config, this);
        qDebug() << "FtpClient:: " << port << " Init connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()))";
        connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()));

        qDebug() << "FtpClient:: " << port << " Init networkSession->open()";
        networkSession->open();
    } else {
        qDebug() << "FtpClient:: Init " << port << " tcpSocket->connectToHost())" << " ipAddress " << ipAddress << " port " << port;
        tcpSocket->connectToHost(QHostAddress(ipAddress),  port);
    }

    mInitiated = true;
}
Exemplo n.º 6
0
void Connector::startRead(qint8 start, qint8 num)
{
    qDebug("start Read");
    exceptByte = 5 + 48 * num;  // 数据头+数据
    qDebug()<<QString("start = %1, num = %2").arg(start).arg(num);
    stopRead();
    connect(this, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
    connect(this, SIGNAL(readAllData()), this, SLOT(handleReadData()));
    this->start = start;
    this->num = num;
    callForData(start, num);
}
Exemplo n.º 7
0
MiniHttpServerConnection::MiniHttpServerConnection(QTcpSocket *socket)
    : QObject(socket), socket(socket), source(0)
{
    connect(socket, SIGNAL(readyRead()), SLOT(handleReadyRead()));
    connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(handleBytesWritten()));
    connect(socket, SIGNAL(disconnected()), SLOT(handleDisconnected()));

    timeout.setInterval(30000);
    timeout.setSingleShot(true);
    connect(&timeout, SIGNAL(timeout()), SLOT(handleTimeout()));
    timeout.start();
}
Exemplo n.º 8
0
MFStream::MFStream(QIODevice *stream, bool ownStream)
    : m_cRef(1)
    , m_stream(stream)
    , m_ownStream(ownStream)
    , m_currentReadResult(0)
{
    //Move to the thread of the stream object
    //to make sure invocations on stream
    //are happened in the same thread of stream object
    this->moveToThread(stream->thread());
    connect(stream, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
}
Exemplo n.º 9
0
void ClientHandler::handleNewConnection()
{
    QTcpServer *server = qobject_cast<QTcpServer *>(sender());

    if ( server )
    {
        QTcpSocket *sock = server->nextPendingConnection();

        QObject::connect(sock, SIGNAL(readyRead()),
                         this, SLOT(handleReadyRead()));
    }

}
Exemplo n.º 10
0
QT_USE_NAMESPACE

SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent)
    : QObject(parent)
    , m_serialPort(serialPort)
    , m_standardOutput(stdout)
{
    connect(m_serialPort, SIGNAL(readyRead()), SLOT(handleReadyRead()));
    connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));
    connect(&m_timer, SIGNAL(timeout()), SLOT(handleTimeout()));

    m_timer.start(5000);
}
Exemplo n.º 11
0
QT_USE_NAMESPACE

SerialPortReader::SerialPortReader(QSerialPort *serialPort, QApplication *app, QQmlApplicationEngine *engine, QObject *parent)
    : QObject(parent)
    , m_serialPort(serialPort)
    , m_app(app),
      m_engine(engine)
{
    connect(m_serialPort, SIGNAL(readyRead()), SLOT(handleReadyRead()));
    connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));
    connect(&m_timer, SIGNAL(timeout()), SLOT(handleTimeout()));

    m_timer.start(5000);
}
Exemplo n.º 12
0
void DeviceMuxer::setDevice(QIODevice* dev)
{
    if (dev == _device)
        return;

    // Disconnect signals from old device
    if (_device) {
        disconnect(_device, SIGNAL(readyRead()),
                this, SLOT(handleReadyRead()));
//        disconnect(_device, SIGNAL(readChannelFinished()),
//                this, SIGNAL(readChannelFinished()));
    }

    QIODevice* oldDev = _device;
    _device = dev;

    // Connect signals to new device
    if (_device) {
        connect(_device, SIGNAL(readyRead()),
                this, SLOT(handleReadyRead()), Qt::QueuedConnection);
    }

    emit deviceChanged(oldDev, _device);
}
Exemplo n.º 13
0
void PTUInterface::connectPort(QString name){
	if(!port->isOpen()){
		// connect signals to slots
		connect(port, SIGNAL(readyRead()), SLOT(handleReadyRead()));
		connect(port, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));

		// set properties
		port->setPortName(name);
		port->open(QIODevice::ReadWrite);
		port->setBaudRate(QSerialPort::Baud9600);
		port->setDataBits(QSerialPort::Data8);
		port->setParity(QSerialPort::NoParity);
		port->setStopBits(QSerialPort::OneStop);
		port->setFlowControl(QSerialPort::NoFlowControl);
	}
}
Exemplo n.º 14
0
void MainWindow::clientConnected()
{

   //Metod je pozvan kada smo se uspesno konektovali
   for(int i=0;i<10000000;i++); //waste time for thread on server to setup
	
   connect(socket, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
   socket->write("REG\n");
   socket->flush();
   socket->waitForReadyRead();
   socket->readAll();
   socket->write(userName->toUtf8());
   socket->flush();
   socket->waitForReadyRead();
   socket->readAll();
   m_bUserNameSend = true;
   ui->textBrowser->setText("Successfully connected.\n");
}
Exemplo n.º 15
0
KeytrackSerial::KeytrackSerial(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::KeytrackSerial)
{
    ui->setupUi(this);
    _serial_port = new QSerialPort(this);

    refreshPortList();

    //Populate baudRate combo box with baud rate options
    ui->baudRate->addItem(QString::number(QSerialPort::Baud1200));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud2400));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud4800));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud9600));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud19200));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud38400));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud57600));
    ui->baudRate->addItem(QString::number(QSerialPort::Baud115200));
    //Preset baud rate selection to 9600
    ui->baudRate->setCurrentText(QString::number(QSerialPort::Baud9600));

    //Populate parity combo box with parity options
    ui->parity->addItem("No Parity");
    ui->parity->addItem("Even Parity");
    ui->parity->addItem("Odd Parity");
    ui->parity->addItem("Space Parity");
    ui->parity->addItem("Mark Parity");

    updatePortSettings();

    connect(ui->connectButton,SIGNAL(clicked()),SLOT(connectPort()));
    connect(ui->disconnectButton, SIGNAL(clicked()),SLOT(disconnectPort()));
    connect(ui->baudRate,SIGNAL(currentTextChanged(QString)),SLOT(updatePortSettings()));
    connect(ui->parity,SIGNAL(currentTextChanged(QString)), SLOT(updatePortSettings()));
    connect(ui->dataBits,SIGNAL(currentTextChanged(QString)),SLOT(updatePortSettings()));
    connect(ui->stopBits,SIGNAL(currentTextChanged(QString)),SLOT(updatePortSettings()));
    connect(_serial_port, SIGNAL(readyRead()),SLOT(handleReadyRead()));
    connect(ui->sendButton,SIGNAL(clicked()),SLOT(sendTextFromBox()));
    connect(ui->sendBox,SIGNAL(returnPressed()),SLOT(sendTextFromBox()));
    connect(this,SIGNAL(destroyed()),SLOT(disconnectPort()));
}
Exemplo n.º 16
0
ClientNet::ClientNet(Logic* pLogic)
:	m_isConnected(false), m_sentBuf(""), m_recvBuf(""),
	m_pLogic(pLogic)
{
	m_pLog = LogManager::getSingleton().getLog("ClientNet");
	// 打开控制台输出开头-注:正式发布时不打开
	m_pLog->setStdStreamActive(true);
	m_pTcpSocket = new QTcpSocket(this);
	// 添加网络消息回调函数
	connect( m_pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
			 this, SLOT(handleError(QAbstractSocket::SocketError)) );
	connect( m_pTcpSocket, SIGNAL(connected()),
			 this, SLOT(handleConnected()) );
	connect( m_pTcpSocket, SIGNAL(readyRead()),
			 this, SLOT(handleReadyRead()) );
	QSettings ini("config.ini", QSettings::IniFormat);
	QString ip = ini.value("ip").toString();
	int32 port = ini.value("port").toInt();
	m_pLog->info(std::string("connect to ") + ip.toLocal8Bit().data() + ":" + SConvert::toString(port));
	m_pTcpSocket->connectToHost(ip, port);
}
Exemplo n.º 17
0
void newConnThread::run()
{
    //this is where the thread actually starts.
    socket = new QTcpSocket;
    if(!socket->setSocketDescriptor(this->socketDescriptor))
    {
        exit(1);
    }
    //cool. we've got a connection.
    //setup timer
    timer = new QTimer;
    timer->start(500);

    //time to connect some signals and slots.
    connect(socket,SIGNAL(readyRead()),this,SLOT(handleReadyRead()));
    connect(socket,SIGNAL(disconnected()),this,SLOT(handleDisconnected()));
    connect(timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
    connect(this,SIGNAL(timeSig()),this,SLOT(handleWrite()));
    //make the thread run even when this run function goes out of scope.
    exec();
}
Exemplo n.º 18
0
void MainWindow::clientConnected()
{
//you are now connected, continue with your execution
//    for(int i=0;i<10000000;i++); //waste time for thread on server to setup
   QThread::sleep(1) ;
   connect(socket, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
   socket->write("REG\n");
   socket->flush();

   socket->waitForReadyRead();

   socket->readAll();
   socket->write(userName->toUtf8());
   socket->flush();
   socket->waitForReadyRead();
   socket->readAll();

   m_bUserNameSend = true;
//   ui->textBrowser->setText("U(pdate) | P(lay) | D(raw) | X(UNO)");
//   ui->textBrowser->append(userName->toUtf8());
}