【发布时间】:2017-07-04 20:09:12
【问题描述】:
大家好,我使用 python 向 qt 发送字符串,但我不知道如何在标签上显示字符串,谁能帮助我??? 我的 mainwindow.cpp 是
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
timer->start();
tcpServer.listen(QHostAddress::Any,42207);
//QByteArray Msg= tcpSocket->readAll();
readMessage();
}
void MainWindow::showTime()
{
QTime time=QTime::currentTime();
QString time_text=time.toString("hh:mm:ss");
ui->Digital_clock->setText(time_text);
QDateTime dateTime = QDateTime::currentDateTime();
QString datetimetext=dateTime.toString();
ui->date->setText(datetimetext);
}
void MainWindow::readMessage()
{
ui->receivedata_2->setText("no connection yet");
if(!tcpServer.listen(QHostAddress::Any,42207))
ui->receivedata_2->setText("waitting!");
//QByteArray Msg= tcpSocket->readAll();
}
每次我尝试放置 socket->readall() 时它都会在我调试时崩溃
【问题讨论】:
-
tcpSocket是什么类型(虽然我猜是QTcpSocket*)以及在哪里初始化它(应该是tcpServer.nextPendingConnection返回的值)?
标签: c++ qt qt5 qtcpsocket qtcpserver