本文整理汇总了C++中QLocalSocket::state方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::state方法的具体用法?C++ QLocalSocket::state怎么用?C++ QLocalSocket::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::state方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qt_connectToServer
void qt_connectToServer()
{
if (!qt_initialized)
return;
// Determine to which server we should connect
QString server = qt_localServerName;
if (!qt_optionWidget.isEmpty())
server = qt_optionWidget;
// Check if we are already connected
if (qt_socket.serverName() == server)
return;
// Disconnect
if (qt_socket.state() == QLocalSocket::ConnectedState)
{
qt_socket.disconnectFromServer();
qt_socket.waitForDisconnected(1000);
}
// Connect to server, or local server if not available.
qt_socket.connectToServer(server);
if (!qt_socket.waitForConnected(3000))
while (qt_socket.state() != QLocalSocket::ConnectedState)
qt_socket.connectToServer(qt_localServerName);
}
示例2: IsAlreadyRunning
bool Application::IsAlreadyRunning () const
{
QLocalSocket socket;
socket.connectToServer (GetSocketName ());
if (socket.waitForConnected () ||
socket.state () == QLocalSocket::ConnectedState)
{
QDataStream out (&socket);
out << Arguments_;
if (socket.waitForBytesWritten ())
return true;
if (socket.error() == QLocalSocket::UnknownSocketError)
return true;
}
else
{
switch (socket.error ())
{
case QLocalSocket::ServerNotFoundError:
case QLocalSocket::ConnectionRefusedError:
break;
default:
qWarning () << Q_FUNC_INFO
<< "socket error"
<< socket.error ();
return true;
}
}
// Clear any halted servers and their messages
QLocalServer::removeServer (GetSocketName ());
return false;
}
示例3: connectToRemote
void connectToRemote(const QString & remoteName)
{
emit pulseOutboundConnect(remoteName);
QMutexLocker locker(&outboundLock);
while (outbound.state() != QLocalSocket::ConnectedState) {
outboundWait.wait(&outboundLock,30*1000);
}
}
示例4: QLocalSocket
RKGraphicsDeviceBackendTransmitter* RKGraphicsDeviceBackendTransmitter::instance () {
if (_instance) return _instance;
RK_TRACE (GRAPHICS_DEVICE);
QLocalSocket *con = new QLocalSocket ();
con->connectToServer (RKRBackendProtocolBackend::rkdServerName ());
con->waitForConnected (2000);
if (con->state () == QLocalSocket::ConnectedState) {
con->write (RKRBackendTransmitter::instance ()->connectionToken ().toLocal8Bit ().data ());
con->write ("\n");
con->waitForBytesWritten (1000);
_instance = new RKGraphicsDeviceBackendTransmitter (con, true);
return _instance;
}
return 0;
}
示例5: qt_waitforinput
int qt_waitforinput(void)
{
#ifdef USE_MOUSE
fd_set read_fds;
int stdin_fd = fileno(stdin);
int socket_fd = qt_socket.socketDescriptor();
if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState))
return getchar();
// Gnuplot event loop
do
{
// Watch file descriptors
FD_ZERO(&read_fds);
FD_SET(socket_fd, &read_fds);
if (!paused_for_mouse)
FD_SET(stdin_fd, &read_fds);
// Wait for input
if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0)
{
fprintf(stderr, "Qt terminal communication error: select() error\n");
break;
}
// Terminal event coming
if (FD_ISSET(socket_fd, &read_fds))
{
qt_socket.waitForReadyRead(-1);
while (qt_socket.bytesAvailable() >= sizeof(gp_event_t))
{
struct gp_event_t event;
qt_socket.read((char*) &event, sizeof(gp_event_t));
/// @todo don't process mouse move events if others are in the queue
if (qt_processTermEvent(&event))
return '\0'; // exit from paused_for_mouse
}
}
} while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds)));
#endif
return getchar();
}
示例6: qDebug
int CurlFtp::closeDataChannel2()
{
QLocalSocket *depSock = this->qdsock2;
qDebug()<<"sock2:"<<depSock<<depSock->isOpen()<<depSock->state();
// this->qdsock2->close();
// delete this->qdsock2;
// this->qdsock2 = NULL;
// this->qdsock2 = NULL;
this->curlWriteDataRouteServer->close();
delete this->curlWriteDataRouteServer;
this->curlWriteDataRouteServer = NULL;
depSock->deleteLater();
// depSock->close();
// delete depSock;
// depSock = NULL;
return 0;
}
示例7: IsAlreadyRunning
bool Application::IsAlreadyRunning () const
{
QLocalSocket socket;
socket.connectToServer (GetSocketName ());
if (socket.waitForConnected () ||
socket.state () == QLocalSocket::ConnectedState)
{
QByteArray toSend;
{
QDataStream out (&toSend, QIODevice::WriteOnly);
out << Arguments_;
}
socket.write (toSend);
socket.disconnectFromServer ();
socket.waitForDisconnected ();
return true;
}
else
{
switch (socket.error ())
{
case QLocalSocket::ServerNotFoundError:
case QLocalSocket::ConnectionRefusedError:
break;
default:
qWarning () << Q_FUNC_INFO
<< "socket error"
<< socket.error ();
return true;
}
}
// Clear any halted servers and their messages
QLocalServer::removeServer (GetSocketName ());
return false;
}
示例8: onNewConnection
void Server::onNewConnection()
{
QLocalSocket* socket = m_server->nextPendingConnection();
if (!socket) {
log("No pending client connections!", LogError);
} else if ( socket->state() != QLocalSocket::ConnectedState ) {
log("Client is not connected!", LogError);
socket->deleteLater();
} else {
QScopedPointer<ClientSocket> clientSocket( new ClientSocket(socket) );
const Arguments args = clientSocket->readArguments();
if ( !args.isEmpty() ) {
++m_socketCount;
connect( clientSocket.data(), SIGNAL(destroyed()),
this, SLOT(onSocketClosed()) );
connect( this, SIGNAL(destroyed()),
clientSocket.data(), SLOT(close()) );
connect( this, SIGNAL(destroyed()),
clientSocket.data(), SLOT(deleteAfterDisconnected()) );
emit newConnection( args, clientSocket.take() );
}
}
}
示例9: main
int main(int argc, char *argv[])
{
qRegisterMetaType<JoyButtonSlot*>();
qRegisterMetaType<InputDevice*>();
qRegisterMetaType<AutoProfileInfo*>();
QTextStream outstream(stdout);
QTextStream errorstream(stderr);
// If running Win version, check if an explicit style
// was defined on the command-line. If so, make a note
// of it.
#ifdef Q_OS_WIN
bool styleChangeFound = false;
for (int i=0; i < argc && !styleChangeFound; i++)
{
char *tempchrstr = argv[i];
QString temp = QString::fromUtf8(tempchrstr);
if (temp == "-style")
{
styleChangeFound = true;
}
}
#endif
CommandLineUtility cmdutility;
QStringList cmdarguments = PadderCommon::arguments(argc, argv);
cmdarguments.removeFirst();
cmdutility.parseArguments(cmdarguments);
Logger appLogger(&outstream, &errorstream);
if (cmdutility.hasError())
{
appLogger.LogError(cmdutility.getErrorText());
return 1;
}
else if (cmdutility.isHelpRequested())
{
appLogger.LogInfo(cmdutility.generateHelpString(), false);
//cmdutility.printHelp();
return 0;
}
else if (cmdutility.isVersionRequested())
{
appLogger.LogInfo(cmdutility.generateVersionString());
//cmdutility.printVersionString();
return 0;
}
if (cmdutility.getCurrentLogLevel() != appLogger.getCurrentLogLevel())
{
appLogger.setLogLevel(cmdutility.getCurrentLogLevel());
}
Q_INIT_RESOURCE(resources);
QDir configDir(PadderCommon::configPath);
if (!configDir.exists())
{
configDir.mkpath(PadderCommon::configPath);
}
QMap<SDL_JoystickID, InputDevice*> *joysticks = new QMap<SDL_JoystickID, InputDevice*>();
// Cross-platform way of performing IPC. Currently,
// only establish a connection and then disconnect.
// In the future, there might be a reason to actually send
// messages to the QLocalServer.
QLocalSocket socket;
socket.connectToServer(PadderCommon::localSocketKey);
socket.waitForConnected(1000);
if (socket.state() == QLocalSocket::ConnectedState)
{
// An instance of this program is already running.
// Save app config and exit.
QApplication a(argc, argv);
AntiMicroSettings settings(PadderCommon::configFilePath, QSettings::IniFormat);
InputDaemon *joypad_worker = new InputDaemon(joysticks, &settings, false);
MainWindow w(joysticks, &cmdutility, &settings, false);
if (!cmdutility.hasError() && cmdutility.hasProfile())
{
w.saveAppConfig();
}
joypad_worker->quit();
w.removeJoyTabs();
settings.sync();
socket.disconnectFromServer();
deleteInputDevices(joysticks);
delete joysticks;
joysticks = 0;
delete joypad_worker;
joypad_worker = 0;
return 0;
//.........这里部分代码省略.........
示例10: qt_waitforinput
int qt_waitforinput(void)
{
#ifdef USE_MOUSE
fd_set read_fds;
int stdin_fd = fileno(stdin);
int socket_fd = qt_socket.socketDescriptor();
if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState))
return getchar();
// Gnuplot event loop
do
{
// Watch file descriptors
FD_ZERO(&read_fds);
FD_SET(socket_fd, &read_fds);
if (!paused_for_mouse)
FD_SET(stdin_fd, &read_fds);
// Wait for input
if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0)
{
// Display the error message except when Ctrl + C is pressed
if (errno != 4)
fprintf(stderr, "Qt terminal communication error: select() error %i %s\n", errno, strerror(errno));
break;
}
// Terminal event coming
if (FD_ISSET(socket_fd, &read_fds))
{
if (!(qt_socket.waitForReadyRead(-1))) {
// Must be a socket error; we need to restart qt_gnuplot
qDebug() << "Error: gnuplot_qt socket not responding";
qt_gnuplot_qtStarted = false;
return '\0';
}
// Temporary event for mouse move events. If several consecutive
// move events are received, only transmit the last one.
gp_event_t tempEvent;
tempEvent.type = -1;
if (qt_socket.bytesAvailable() < sizeof(gp_event_t)) {
qDebug() << "Error: short read from gnuplot_qt socket";
return '\0';
}
while (qt_socket.bytesAvailable() >= sizeof(gp_event_t))
{
struct gp_event_t event;
qt_socket.read((char*) &event, sizeof(gp_event_t));
// Delay move events
if (event.type == GE_motion)
tempEvent = event;
// Other events. Replay the last move event if present
else
{
if (tempEvent.type == GE_motion)
{
qt_processTermEvent(&tempEvent);
tempEvent.type = -1;
}
if (qt_processTermEvent(&event))
return '\0'; // exit from paused_for_mouse
}
}
// Replay move event
if (tempEvent.type == GE_motion)
qt_processTermEvent(&tempEvent);
}
} while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds)));
#endif
return getchar();
}
示例11: 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;
}
}
示例12: main
int main(int argc, char *argv[])
{
qRegisterMetaType<JoyButtonSlot*>();
qRegisterMetaType<AdvanceButtonDialog*>();
//qRegisterMetaType<Joystick*>();
qRegisterMetaType<InputDevice*>();
// If running Win version, check if an explicit style
// was defined on the command-line. If so, make a note
// of it.
#ifdef Q_OS_WIN
bool styleChangeFound = false;
for (int i=0; i < argc && !styleChangeFound; i++)
{
char *tempchrstr = argv[i];
QString temp = QString::fromUtf8(tempchrstr);
if (temp == "-style")
{
styleChangeFound = true;
}
}
#endif
QApplication a(argc, argv);
//QString defaultStyleName = qApp->style()->objectName();
// If running Win version and no explicit style was
// defined, use the style Fusion by default. I find the
// windowsvista style a tad ugly
#ifdef Q_OS_WIN
if (!styleChangeFound)
{
qApp->setStyle(QStyleFactory::create("Fusion"));
}
#endif
CommandLineUtility cmdutility;
QStringList cmdarguments = a.arguments();
cmdutility.parseArguments(cmdarguments);
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
a.installTranslator(&qtTranslator);
QTranslator myappTranslator;
#if defined(Q_OS_UNIX)
myappTranslator.load("antimicro_" + QLocale::system().name(), QApplication::applicationDirPath().append("/../share/antimicro/translations"));
#elif defined(Q_OS_WIN)
myappTranslator.load("antimicro_" + QLocale::system().name(), QApplication::applicationDirPath().append("\\share\\antimicro\\translations"));
#endif
a.installTranslator(&myappTranslator);
if (cmdutility.hasError())
{
return 1;
}
else if (cmdutility.isHelpRequested())
{
cmdutility.printHelp();
return 0;
}
else if (cmdutility.isVersionRequested())
{
cmdutility.printVersionString();
return 0;
}
Q_INIT_RESOURCE(resources);
a.setQuitOnLastWindowClosed(false);
QDir configDir (PadderCommon::configPath);
if (!configDir.exists())
{
configDir.mkpath(PadderCommon::configPath);
}
#ifdef USE_SDL_2
QHash<SDL_JoystickID, InputDevice*> *joysticks = new QHash<SDL_JoystickID, InputDevice*>();
#else
QHash<int, InputDevice*> *joysticks = new QHash<int, InputDevice*>();
#endif
// Cross-platform way of performing IPC. Currently,
// only establish a connection and then disconnect.
// In the future, there might be a reason to actually send
// messages to the QLocalServer.
QLocalSocket socket;
socket.connectToServer(PadderCommon::localSocketKey);
socket.waitForConnected(1000);
if (socket.state() == QLocalSocket::ConnectedState)
{
// An instance of this program is already running.
// Save app config and exit.
InputDaemon *joypad_worker = new InputDaemon(joysticks, false);
MainWindow w(joysticks, &cmdutility, false);
if (!cmdutility.hasError() && cmdutility.hasProfile())
{
w.saveAppConfig();
}
//.........这里部分代码省略.........