QString to char* conversion

前端 未结 10 2106
予麋鹿
予麋鹿 2020-11-27 02:57

I was trying to convert a QString to char* type by the following methods, but they don\'t seem to work.

//QLineEdit *line=new QLineEdit();{just to describe w         


        
10条回答
  •  心在旅途
    2020-11-27 03:17

    Maybe

    my_qstring.toStdString().c_str();

    or safer, as Federico points out:

    std::string str = my_qstring.toStdString();
    const char* p = str.c_str();
    

    It's far from optimal, but will do the work.

提交回复
热议问题