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));
}
}