错误记录:QString转const char* 问题

//错误写法:
//    const char *device = ((ui->portComboBox->currentText()).toStdString()).data();  //读取串口名
//正确写法:
    QString str = ui->portComboBox->currentText();
    QByteArray byte = str.toLocal8Bit();
    const char *device = byte.data();  //读取串口名
    qDebug()<

按照错误写法: 连写               不会报错,运行时读设备号为 0



按照正确写法:分开写            运行能够正确读取设备号


猜你喜欢

转载自blog.csdn.net/qq_19875391/article/details/62231594