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


C++ QLocalSocket::flush方法代码示例

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


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

示例1: ipcSendCommandLine

//
// Sending to the server is done synchronously, at startup.
// If the server isn't already running, startup continues,
// and the items in savedPaymentRequest will be handled
// when uiReady() is called.
//
bool PaymentServer::ipcSendCommandLine()
{
    bool fResult = false;
    for (const QString& r : savedPaymentRequests)
    {
        QLocalSocket* socket = new QLocalSocket();
        socket->connectToServer(ipcServerName(), QIODevice::WriteOnly);
        if (!socket->waitForConnected(BITCOIN_IPC_CONNECT_TIMEOUT))
        {
            delete socket;
            socket = nullptr;
            return false;
        }

        QByteArray block;
        QDataStream out(&block, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_4_0);
        out << r;
        out.device()->seek(0);

        socket->write(block);
        socket->flush();
        socket->waitForBytesWritten(BITCOIN_IPC_CONNECT_TIMEOUT);
        socket->disconnectFromServer();

        delete socket;
        socket = nullptr;
        fResult = true;
    }

    return fResult;
}
开发者ID:TinyUlt,项目名称:bitcoin,代码行数:38,代码来源:paymentserver.cpp

示例2: rpcCall

void IPCEngineHost::rpcCall(Function f, QByteArray payload)
{
    if (m_localGuest) {
        QMetaObject::invokeMethod(m_localGuest,
                "rpcCallback",
                Qt::QueuedConnection,
                Q_ARG(quint64, f),
                Q_ARG(QByteArray, payload));
    } else if (m_device) {
        QByteArray header;
        {
            QDataStream s(&header, QIODevice::WriteOnly);
            SET_NATIVE_BYTE_ORDER(s);
            s << m_cookie++;
            s << (quint64) f;
            s << (quint64) payload.size();
        }
        m_device->write(header);
        m_device->write(payload);
        m_device->putChar('T');
        QLocalSocket *sock = qobject_cast<QLocalSocket *>(m_device);
        if (sock)
            sock->flush();
    }
}
开发者ID:pcacjr,项目名称:qt-creator,代码行数:25,代码来源:ipcenginehost.cpp

示例3: QLocalSocket

bool N810GpsPlugin::sendToGpsDriverCtrl(QString cmd)
{
    QLocalSocket *gpsCtrlSocket;
    gpsCtrlSocket = new QLocalSocket(this);

    QByteArray socketPath = ( "/var/lib/gps/gps_driver_ctrl");
    gpsCtrlSocket->connectToServer(socketPath.data());

    if(gpsCtrlSocket->waitForConnected()) {
        qLog(Hardware)<< __PRETTY_FUNCTION__ << "connected" << cmd;

        QByteArray data;
        data.append(cmd);
        data.append("\n");
        gpsCtrlSocket->write(data);


        gpsCtrlSocket->flush();
        gpsCtrlSocket->disconnectFromServer();
        return true;
    } else {
        qLog(Hardware) << __PRETTY_FUNCTION__ << "Could not connect to socket" << gpsCtrlSocket;
    }
    return false;
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:25,代码来源:n810gpsplugin.cpp

示例4: retrieveData

bool MonavRunnerPrivate::retrieveData( const RouteRequest *route, const QString &mapDir, RoutingResult* reply ) const
{
    QLocalSocket socket;
    socket.connectToServer( "MoNavD" );
    if ( socket.waitForConnected() ) {
        if ( m_plugin->monavVersion() == MonavPlugin::Monav_0_3 ) {
            CommandType commandType;
            commandType.value = CommandType::RoutingCommand;
            commandType.post( &socket );
        }

        RoutingCommand command;
        QVector<Node> waypoints;

        for ( int i = 0; i < route->size(); ++i ) {
            Node coordinate;
            coordinate.longitude = route->at( i ).longitude( GeoDataCoordinates::Degree );
            coordinate.latitude = route->at( i ).latitude( GeoDataCoordinates::Degree );
            waypoints << coordinate;
        }

        command.dataDirectory = mapDir;
        command.lookupRadius = 1500;
        command.waypoints = waypoints;
        command.lookupStrings = true;

        command.post( &socket );
        socket.flush();

        if ( reply->read( &socket ) ) {
            switch ( reply->type ) {
            case RoutingResult::LoadFailed:
                mDebug() << "failed to load monav map from " << mapDir;
                return false;
                break;
            case RoutingResult::RouteFailed:
                mDebug() << "failed to retrieve route from monav daemon";
                return false;
                break;
            case RoutingResult::TypeLookupFailed:
                mDebug() << "failed to lookup type from monav daemon";
                return false;
                break;
            case RoutingResult::NameLookupFailed:
                mDebug() << "failed to lookup name from monav daemon";
                return false;
                break;
            case RoutingResult::Success:
                return true;
            }
        } else {
            mDebug() << "Failed to read reply";
        }
    } else {
        mDebug() << "No connection to MoNavD";
    }

    return false;
}
开发者ID:KDE,项目名称:marble,代码行数:59,代码来源:MonavRunner.cpp

示例5: sendResponse

void YACReaderLocalServer::sendResponse()
{
	/*QLocalSocket *clientConnection = localServer->nextPendingConnection();

    connect(clientConnection, SIGNAL(disconnected()),
            clientConnection, SLOT(deleteLater()));

    QDataStream in(clientConnection);
    in.setVersion(QDataStream::Qt_4_0);

    if (clientConnection->bytesAvailable() == 0)
		return;
 
    if (in.atEnd())
        return;

    QString message;
    in >> message;

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    out << QString("OK");

    clientConnection->write(block);
    clientConnection->flush();
    clientConnection->disconnectFromServer();*/

	     QByteArray block;
     QDataStream out(&block, QIODevice::WriteOnly);
     out.setVersion(QDataStream::Qt_4_0);
     out << (quint16)0;
     out << QString("ok");
     out.device()->seek(0);
     out << (quint16)(block.size() - sizeof(quint16));

     QLocalSocket *clientConnection = localServer->nextPendingConnection();
     connect(clientConnection, SIGNAL(disconnected()),
             clientConnection, SLOT(deleteLater()));

     clientConnection->write(block);
     clientConnection->flush();
     clientConnection->disconnectFromServer();

}
开发者ID:Skelly1983,项目名称:yacreader,代码行数:45,代码来源:yacreader_local_server.cpp

示例6: sendFortune

void Server::sendFortune()
{
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    out << (quint16)0;
    out << fortunes.at(qrand() % fortunes.size());
    out.device()->seek(0);
    out << (quint16)(block.size() - sizeof(quint16));

    QLocalSocket *clientConnection = server->nextPendingConnection();
    connect(clientConnection, SIGNAL(disconnected()),
            clientConnection, SLOT(deleteLater()));

    clientConnection->write(block);
    clientConnection->flush();
    clientConnection->disconnectFromServer();
}
开发者ID:eagafonov,项目名称:qtmoko,代码行数:18,代码来源:server.cpp

示例7: main

int main(int argc, char *argv[])
{

#if QT_NO_DEBUG
    QLocalSocket socket;
    socket.connectToServer(SERVER);
    if(socket.waitForConnected(1000))
    {
        if (argc == 2)
        {

            socket.write(argv[1]);
            socket.flush();
            socket.waitForBytesWritten();

        }
        socket.disconnectFromServer();

        exit(0);
    }
    else
    {
        if (argc != 1)
            exit(0);

    }
#endif

    QApplication a(argc, argv);
    MainWindow w;





    QTranslator translator ;
    translator.load("/usr/share/qt/translations/qt_cs");
    a.installTranslator(&translator);

    //w.show();
    
    return a.exec();

}
开发者ID:kubanecxxx,项目名称:xrandr,代码行数:44,代码来源:main.cpp

示例8: callback_read_file

size_t callback_read_file(void *ptr, size_t size, size_t nmemb, void *userp)
{
    // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<size<<nmemb<<userp;

    size_t tlen = size * nmemb, rlen = 0;
    QBuffer strbuf;
    QByteArray line;
    int n = 0, wlen = 0;

    CurlFtp *ftp = static_cast<CurlFtp*>(userp);
    QLocalSocket *router = ftp->getDataSock2();

    strbuf.setData((const char*)ptr, tlen);
    strbuf.open(QBuffer::ReadOnly);
    // Q_ASSERT(strbuf.canReadLine()); //  ???
    rlen = 0;
    while (!strbuf.atEnd()) {
        if (strbuf.canReadLine()) {
            line = strbuf.readLine();
        } else {
            line = strbuf.readAll();
        }
        rlen += line.length();
        wlen = router->write(line);
        // qDebug()<<"Line: "<<n++<<line.length()<<wlen;
        // fprintf(stdout, "%s", ".");
        // fflush(stdout);
        Q_ASSERT(line.length() == wlen);
        // break;
    }
    strbuf.close();
    router->flush();

    // qDebug()<<"can rw:"<<router->isReadable()<<router->isWritable()<<router->isOpen();
    // fprintf(stdout, "route read file:. %p %d %s", router, router->bytesAvailable(), "\n");
    fflush(stdout);

    return rlen;
    return 0;
}
开发者ID:caidongyun,项目名称:nullfxp,代码行数:40,代码来源:curlftp_callback.cpp

示例9: openFileOnRemote

bool mASocketManager::openFileOnRemote(const QString &_path)
{
    bool r = false;
    
    QString path = QFileInfo(_path).canonicalFilePath();
    path.append('\n');
    
    QLocalSocket socket;
    socket.connectToServer(MA_LOCAL_SERVER_NAME);
    
    if(socket.waitForConnected(MAX_TIMEOUT_CLIENT))
    {
        socket.write(path.toUtf8());
        socket.flush();
        socket.waitForBytesWritten(MAX_TIMEOUT_CLIENT);
        r = true;
    }
    
    socket.close();
    
    return r;
}
开发者ID:ccrma,项目名称:miniAudicle,代码行数:22,代码来源:mASocketManager.cpp

示例10: main

int main( int argc, char *argv[] ) {
	CommandType commandType;
	UnpackCommand unpackCommand;
	RoutingCommand routingCommand;
	routingCommand.lookupStrings = true;

	if ( !processArguments( &commandType, &unpackCommand, &routingCommand, argc, argv ) ) {
		qDebug() << "usage:" << argv[0] << "data-directory latitude1 longitude1 latitude2 longitude2 [...latitudeN longitudeN]";
		qDebug() << "\tcomputes a route using between the specified waypoints";
		qDebug() << "usage:" << argv[0] << "monav-map-module-file";
		qDebug() << "\tunpacks a map module";
		return 1;
	}

	QLocalSocket connection;
	connection.connectToServer( "MoNavD" );
	if ( !connection.waitForConnected() ) {
		qDebug() << "failed to connect to daemon:" << connection.error();
		return 2;
	}

	commandType.post( &connection );

	if ( commandType.value == CommandType::UnpackCommand ) {
		unpackCommand.post( &connection );
		connection.flush();
		UnpackResult reply;
		reply.type = UnpackResult::FailUnpacking;
		reply.read( &connection );
		qDebug() << connection.state();

		if ( reply.type == UnpackResult::FailUnpacking ) {
			qDebug() << "failed to unpack map file";
			return 3;
		}
		qDebug() << "finished unpacking map file";
		return 0;
	}

	routingCommand.post( &connection );
	connection.flush();
	RoutingResult reply;
	reply.read( &connection );
	qDebug() << connection.state();

	if ( reply.type == RoutingResult::LoadFailed ) {
		qDebug() << "failed to load data directory";
		return 3;
	} else if ( reply.type == RoutingResult::RouteFailed ) {
		qDebug() << "failed to compute route";
		return 3;
	} else if ( reply.type == RoutingResult::NameLookupFailed ) {
		qDebug() << "failed to compute route";
		return 3;
	} else if ( reply.type == RoutingResult::TypeLookupFailed ) {
		qDebug() << "failed to compute route";
		return 3;
	}else if ( reply.type == RoutingResult::Success ) {
		int seconds = reply.seconds;
		qDebug() << "distance:" << seconds / 60 / 60 << "h" << ( seconds / 60 ) % 60 << "m" << seconds % 60 << "s";
		qDebug() << "nodes:" << reply.pathNodes.size();
		qDebug() << "edges:" << reply.pathEdges.size();

		unsigned node = 0;
		for ( int i = 0; i < reply.pathEdges.size(); i++ ) {
			QString name = reply.nameStrings[reply.pathEdges[i].name];
			QString type = reply.typeStrings[reply.pathEdges[i].type];
			qDebug() << "name:" << name.toUtf8() << "type:" << type << "nodes:" << reply.pathEdges[i].length + 1 << "seconds:" << reply.pathEdges[i].seconds << "branching possible:" << reply.pathEdges[i].branchingPossible;
			for ( unsigned j = 0; j <= reply.pathEdges[i].length; j++ ) {
				QString latitude, longitude;
				latitude.setNum( reply.pathNodes[j + node].latitude, 'g', 10 );
				longitude.setNum( reply.pathNodes[j + node].longitude, 'g', 10 );
				qDebug() << latitude.toLatin1().data() << longitude.toLatin1().data();
			}
			node += reply.pathEdges[i].length;
		}
	} else {
		qDebug() << "return value not recognized";
		return 5;
	}
}
开发者ID:waitman,项目名称:monav,代码行数:81,代码来源:test.cpp

示例11: serverName

ApplicationCore::ApplicationCore(TaskId startupTask, bool hideAtStart, QObject *parent)
    : QObject(parent)
    , m_actionStopAllTasks(this)
    , m_actionQuit(this)
    , m_actionAboutDialog(this)
    , m_actionPreferences(this)
    , m_actionExportToXml(this)
    , m_actionImportFromXml(this)
    , m_actionSyncTasks(this)
    , m_actionImportTasks(this)
    , m_actionExportTasks(this)
    , m_actionCheckForUpdates(this)
    , m_actionEnterVacation(this)
    , m_actionActivityReport(this)
    , m_actionWeeklyTimesheetReport(this)
    , m_actionMonthlyTimesheetReport(this)
    , m_uiElements(
{
    &m_timeTracker, &m_tasksView, &m_eventView
}),
    m_startupTask(startupTask)
  , m_hideAtStart(hideAtStart)

#ifdef Q_OS_WIN
    , m_windowsJumpList(new QWinJumpList(this))
#endif
    , m_dateChangeWatcher(new DateChangeWatcher(this))
{
    // QApplication setup
    QApplication::setQuitOnLastWindowClosed(false);
    // application metadata setup
    // note that this modifies the behaviour of QSettings:
    QCoreApplication::setOrganizationName(QStringLiteral("KDAB"));
    QCoreApplication::setOrganizationDomain(QStringLiteral("kdab.com"));
    QCoreApplication::setApplicationName(QStringLiteral("Charm"));
    QCoreApplication::setApplicationVersion(CharmVersion());

    QLocalSocket uniqueApplicationSocket;
    QString serverName(QStringLiteral("com.kdab.charm"));
    QString charmHomeEnv(QString::fromLocal8Bit(qgetenv("CHARM_HOME")));
    if (!charmHomeEnv.isEmpty()) {
        serverName.append(QStringLiteral("_%1").arg(
                              charmHomeEnv.replace(QRegExp(QLatin1String(":?/|:?\\\\")),
                                                   QStringLiteral("_"))));
    }
#ifndef NDEBUG
    serverName.append(QStringLiteral("_debug"));
#endif
    uniqueApplicationSocket.connectToServer(serverName, QIODevice::ReadWrite);
    if (uniqueApplicationSocket.waitForConnected(1000)) {
        QByteArray command;
        if (startupTask != -1) {
            command = StartTaskCommand + QByteArray::number(startupTask);
        } else {
            command = RaiseWindowCommand;
        }
        command += '\n';
        qint64 written = uniqueApplicationSocket.write(command);
        if (written == -1 || written != command.length()) {
            qWarning() << "Failed to pass " << command << " to running charm instance, error: "
                        << uniqueApplicationSocket.errorString();
        }
        uniqueApplicationSocket.flush();
        uniqueApplicationSocket.waitForBytesWritten();
        throw AlreadyRunningException();
    }

    connect(&m_uniqueApplicationServer, &QLocalServer::newConnection,
            this, &ApplicationCore::slotHandleUniqueApplicationConnection, Qt::QueuedConnection);

    QFile::remove(QDir::tempPath() + QLatin1Char('/') + serverName);
    bool listening = m_uniqueApplicationServer.listen(serverName);
    if (!listening)
        qDebug() << "Failed to create QLocalServer for unique application support:"
                 << m_uniqueApplicationServer.errorString();

    Q_INIT_RESOURCE(CharmResources);
    Q_ASSERT_X(m_instance == 0, "Application ctor",
               "Application is a singleton and cannot be created more than once");
    m_instance = this;
    qRegisterMetaType<State>("State");
    qRegisterMetaType<Event>("Event");

    // exit process (app will only exit once controller says it is ready)
    connect(&m_controller, &Controller::readyToQuit,
            this, &ApplicationCore::slotControllerReadyToQuit);

    connectControllerAndModel(&m_controller, m_model.charmDataModel());
    Charm::connectControllerAndView(&m_controller, &m_timeTracker);

    // save the configuration (configuration is managed by the application)
    connect(&m_timeTracker, &CharmWindow::saveConfiguration,
            this, &ApplicationCore::slotSaveConfiguration);
    connect(&m_timeTracker, &TimeTrackingWindow::showNotification,
            this, &ApplicationCore::slotShowNotification);
    connect(&m_timeTracker, &TimeTrackingWindow::taskMenuChanged,
            this, &ApplicationCore::slotPopulateTrayIconMenu);

    // save the configuration (configuration is managed by the application)
    connect(&m_tasksView, &TasksView::saveConfiguration,
//.........这里部分代码省略.........
开发者ID:KDAB,项目名称:Charm,代码行数:101,代码来源:ApplicationCore.cpp


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