当前位置: 首页>>代码示例>>C++>>正文


C++ QTcpSocket::setParent方法代码示例

本文整理汇总了C++中QTcpSocket::setParent方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::setParent方法的具体用法?C++ QTcpSocket::setParent怎么用?C++ QTcpSocket::setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTcpSocket的用法示例。


在下文中一共展示了QTcpSocket::setParent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ConnectionBackend

ConnectionBackend *ConnectionBackend::nextPendingConnection()
{
    Q_ASSERT(state == Listening);
    Q_ASSERT(localServer || tcpServer);
    Q_ASSERT(!socket);

    //qCDebug(KIO_CORE) << "Got a new connection";

    QTcpSocket *newSocket;
    if (mode == LocalSocketMode) {
        newSocket = localServer->nextPendingConnection();
    } else {
        newSocket = tcpServer->nextPendingConnection();
    }

    if (!newSocket) {
        return 0;    // there was no connection...
    }

    ConnectionBackend *result = new ConnectionBackend(Mode(mode));
    result->state = Connected;
    result->socket = newSocket;
    newSocket->setParent(result);
    connect(newSocket, SIGNAL(readyRead()), result, SLOT(socketReadyRead()));
    connect(newSocket, SIGNAL(disconnected()), result, SLOT(socketDisconnected()));

    return result;
}
开发者ID:emmanuel099,项目名称:kio,代码行数:28,代码来源:connectionbackend.cpp

示例2: run

void NetworkManagerThread::run(){

    _server = new QTcpServer();

    int retryCount = 0;
    bool success = false;
    while(!success && retryCount < 40){
        success = this->_server->listen(QHostAddress::Any, Config::current()->serverPort()+1);
        retryCount++;

        if(!success)
            msleep(200);
    }

    if(!success){
        Log::add(tr("Could not listen on port %1").arg(QString::number(Config::current()->serverPort()+1)), Log::Error);
        return;
    }


    bool ok;
    while(true){
        /*
          Eingebauter Stopp 1
          */
        this->checkSuspended();
        if(!_server)
            return;
        _server->waitForNewConnection(1000,&ok);
        if(!ok){
            /*
              Eingebauter Stop 2
              */
            this->checkSuspended();

            QTcpSocket *connection = _server->nextPendingConnection();
            if(connection == 0)
                continue;

            Log::add(tr("New connection from %1").arg(connection->peerAddress().toString()), Log::Information);

            RootConsoleThread *thread = new RootConsoleThread(connection);
            connection->setParent(0);
            connection->moveToThread(thread);

            this->_runningConsoles.append(thread);
            this->_sockets.append(connection);

            thread->start();
        }
    }


}
开发者ID:okirmis,项目名称:sdb-server,代码行数:54,代码来源:networkmanagerthread.cpp

示例3: _q_onNewConnection

void QLocalServerPrivate::_q_onNewConnection()
{
    Q_Q(QLocalServer);
    QTcpSocket* tcpSocket = tcpServer.nextPendingConnection();
    if (!tcpSocket) {
        qWarning("QLocalServer: no pending connection");
        return;
    }

    tcpSocket->setParent(q);
    const quintptr socketDescriptor = tcpSocket->socketDescriptor();
    q->incomingConnection(socketDescriptor);
}
开发者ID:Suneal,项目名称:qt,代码行数:13,代码来源:qlocalserver_tcp.cpp

示例4: newConnection

void TcpListener::newConnection() {
  QTcpSocket *socket = _server->nextPendingConnection();
  if (!socket) // should never happen
    return;
  Session session = SessionManager::createSession();
  QString clientaddr = "["+socket->peerAddress().toString()
      +"]:"+QString::number(socket->peerPort());
  session.setParam("clientaddr", clientaddr);
  if (_idleHandlers.size() == 0) {
    Log::warning(session.id()) << "cannot handle connection: no idle handler"
                               << clientaddr;
    // LATER leave a reply to client
    delete socket;
  } else {
    TcpConnectionHandler *handler = _idleHandlers.takeFirst();
    socket->setParent(0);
    socket->moveToThread(handler->thread());
    handler->processConnection(socket, session);
  }
}
开发者ID:g76r,项目名称:libqtssu,代码行数:20,代码来源:tcplistener.cpp

示例5: run

void NetworkServiceProvider::run(){

    bool dbAvail = false;

    while(!dbAvail){
        msleep(100);
        QList<ProcessManager::Process*> processes = ProcessManager::instance()->processesFromClassName("SearchStorageThread");
        if(processes.isEmpty()){
            dbAvail = false;
        }else{
            if(processes.first()->description == "Saves search databases"){
                break;
            }
        }
    }

    this->_serverSocket = new QTcpServer(this);

    int retryCount = 0;
    bool success = false;
    while(!success && retryCount < 40){
        success = this->_serverSocket->listen(QHostAddress::Any, Config::current()->serverPort());
        retryCount++;

        if(!success)
            msleep(200);
    }

    if(!success){
        Log::add(tr("Could not listen on port %1").arg(QString::number(Config::current()->serverPort())), Log::Error);
        return;
    }


    Log::add(tr("Bringing search interface up"),Log::Information);

    forever{
        if(_stop){
            break;
        }
        bool ok;
        this->_serverSocket->waitForNewConnection(500,&ok);

        this->checkForFinishedThreads();

        //Kein Timeout sondern verbindung
        if(!ok){

            QTcpSocket *socket = this->_serverSocket->nextPendingConnection();
            if(!socket)
                continue;
            socket->setParent(0);

            SearchRequestHandler *handler = new SearchRequestHandler(socket);
            socket->moveToThread(handler);

            connect(handler,SIGNAL(finished()),handler,SLOT(cleanUp()));
            this->_requests.append(handler);

            handler->start();


        }
    }
    _stopped = true;
}
开发者ID:okirmis,项目名称:sdb-server,代码行数:66,代码来源:networkserviceprovider.cpp


注:本文中的QTcpSocket::setParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。