本文整理汇总了C++中QLocalSocket::setProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::setProperty方法的具体用法?C++ QLocalSocket::setProperty怎么用?C++ QLocalSocket::setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::setProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: in
Server::Server(QString servername, QObject *parent) : QObject(parent){
qDebug() << "Starting server...";
m_server = new QLocalServer(this);
while(!m_server->listen(servername)){
if(m_server->serverError() == QAbstractSocket::AddressInUseError){
qDebug() << m_server->serverError() << "\nCalling removeServer...";
m_server->removeServer(servername);
}else{
qDebug() << "Not able to start the server!\n" << m_server->serverError();
}
}
if (m_server->isListening())
qDebug() << "Server started.\n\n";
clientID = 0;
connect(m_server, &QLocalServer::newConnection, [this](){
clientID++;
QLocalSocket *sock = m_server->nextPendingConnection();
clients.insert(clientID, sock);
sock->setProperty("ID", QVariant(clientID));
sock->setProperty("BTR", QVariant(0));
QObject::connect(sock, &QLocalSocket::readyRead, [this, sock](){
QDataStream in(sock);
in.setVersion(QDataStream::Qt_5_0);
if(sock->property("BTR").toInt() == 0){
quint64 btr;
in >> btr;
sock->setProperty("BTR", QVariant(btr));
}
if(sock->bytesAvailable() < sock->property("BTR").toInt())
return;
QString message;
in >> message;
sock->setProperty("BTR", QVariant(0));
emit newMessageFromClient(sock->property("ID").toInt(), message);
});