QString的toStdString().c_str()坑

host不能被使用,因为被释放了。ip.toStdString()返回的临时对象被释放。

QString ip = ui->lineEdit_IP->text();
const char* host = ip.toStdString().c_str(); //此行结束,临时对象被释放

建议在需要host的地方,直接写 ip.toStdString().c_str()

posted @ 2025-03-17 11:27  夕西行  阅读(13)  评论(0)    收藏  举报