赞
踩
- void Widget::readyRead_slot()
- {
- //读取服务器发来的数据
- QByteArray msg = socket->readAll();
- QString str = QString::fromLocal8Bit(msg);
- QStringList list = str.split(':');
- if(list.at(0)== userName)
- {
-
- QString str2;
-
- for (int i = 1; i < list.count(); ++i) {
- str2 += list.at(i); //拼接字符串
- }
-
- str2 += ":";
- str2 += list.at(0);
-
- // 直接在添加新项时设置对齐方式
- QListWidgetItem* item = new QListWidgetItem(str2, ui->listWidget);
- item->setTextAlignment(Qt::AlignRight);
- }
- //将数据放入ui界面
- else
- {
- ui->listWidget->addItem(QString::fromLocal8Bit(msg));
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。