qstring

How to use std::string in a QLineEdit?

别来无恙 提交于 2021-02-16 13:31:31
问题 I have the following problem. I am trying to integrate a large code written by me with a Qt interface. Some of my functions return std::string . I did not succeed in making QLineEdit::setText accept them (other functions returning char do not give me problems). What should I do? Thanks! Giuseppe 回答1: Try this: std::string a = "aaa"; lineEdit->setText(QString::fromStdString(a)); You will need Qt with STL support. 回答2: There's no constructor for QString that takes a std::string . Convert it

How to use std::string in a QLineEdit?

我怕爱的太早我们不能终老 提交于 2021-02-16 13:29:09
问题 I have the following problem. I am trying to integrate a large code written by me with a Qt interface. Some of my functions return std::string . I did not succeed in making QLineEdit::setText accept them (other functions returning char do not give me problems). What should I do? Thanks! Giuseppe 回答1: Try this: std::string a = "aaa"; lineEdit->setText(QString::fromStdString(a)); You will need Qt with STL support. 回答2: There's no constructor for QString that takes a std::string . Convert it

QString New Line

房东的猫 提交于 2021-02-10 07:14:00
问题 I want to add a new line to my QString . I tried to use \n , but I am receiving an error of "Expected Expression". An example of my code can be found below: if (ui->lineEdit_Company_Name->text().isEmpty()) ErrorLog = ErrorLog + "Company Name is empty", \r\n; if(ui->lineEdit_Company_Owner->text().isEmpty()) ErrorLog = ErrorLog + "Company Owner is empty", \r\n; 回答1: You need to use operator+, push_back, append or some other means for appending when using std::string , QString and the like.

QString New Line

我只是一个虾纸丫 提交于 2021-02-10 07:06:51
问题 I want to add a new line to my QString . I tried to use \n , but I am receiving an error of "Expected Expression". An example of my code can be found below: if (ui->lineEdit_Company_Name->text().isEmpty()) ErrorLog = ErrorLog + "Company Name is empty", \r\n; if(ui->lineEdit_Company_Owner->text().isEmpty()) ErrorLog = ErrorLog + "Company Owner is empty", \r\n; 回答1: You need to use operator+, push_back, append or some other means for appending when using std::string , QString and the like.

QString New Line

≡放荡痞女 提交于 2021-02-10 07:06:43
问题 I want to add a new line to my QString . I tried to use \n , but I am receiving an error of "Expected Expression". An example of my code can be found below: if (ui->lineEdit_Company_Name->text().isEmpty()) ErrorLog = ErrorLog + "Company Name is empty", \r\n; if(ui->lineEdit_Company_Owner->text().isEmpty()) ErrorLog = ErrorLog + "Company Owner is empty", \r\n; 回答1: You need to use operator+, push_back, append or some other means for appending when using std::string , QString and the like.

QString New Line

痞子三分冷 提交于 2021-02-10 07:06:08
问题 I want to add a new line to my QString . I tried to use \n , but I am receiving an error of "Expected Expression". An example of my code can be found below: if (ui->lineEdit_Company_Name->text().isEmpty()) ErrorLog = ErrorLog + "Company Name is empty", \r\n; if(ui->lineEdit_Company_Owner->text().isEmpty()) ErrorLog = ErrorLog + "Company Owner is empty", \r\n; 回答1: You need to use operator+, push_back, append or some other means for appending when using std::string , QString and the like.

Format a Number to a specific QString format

穿精又带淫゛_ 提交于 2021-02-07 11:25:20
问题 I have a question about formatting a decimal number to a certain QString format. Basically, I have an input box in my program that can take any values. I want it to translate the value in this box to the format "+05.30" (based on the value). The value will be limited to +/-99.99. Some examples include: .2 --> +00.02 -1.5 --> -01.50 9.9 --> +09.90 I'm thinking of using a converter like this, but it will have some obvious issues (no leading 0, no leading + sign). QString temp = QString::number

Format a Number to a specific QString format

谁都会走 提交于 2021-02-07 11:25:13
问题 I have a question about formatting a decimal number to a certain QString format. Basically, I have an input box in my program that can take any values. I want it to translate the value in this box to the format "+05.30" (based on the value). The value will be limited to +/-99.99. Some examples include: .2 --> +00.02 -1.5 --> -01.50 9.9 --> +09.90 I'm thinking of using a converter like this, but it will have some obvious issues (no leading 0, no leading + sign). QString temp = QString::number

How to convert Q_ENUM to QString for QT > 5.11 most efficient way?

不问归期 提交于 2021-02-05 08:51:35
问题 I read several advices how to get an actual QString from a Q_ENUM value. Below are 3 possible ways, I came up with, that are compilable constructs in QT5.11.1 What of them should one prefer and why? void MainWindow::setErrorText(QCanBusDevice::CanBusError error) { QString errorString; QDebug(&errorString) << error; ui->statusBar->showMessage("Error occured: " + errorString); // QT4 ? const QMetaObject& mo = QCanBusDevice::staticMetaObject; QMetaEnum me = mo.enumerator(mo.indexOfEnumerator(

Converting QString to Ascii value & Vice Versa in Qt

回眸只為那壹抹淺笑 提交于 2021-02-04 15:52:25
问题 I have a QString StrData = "abcd" and I want get the Ascii value in hex of that string and Vice Versa. For example from "abcd" to "61 62 63 64" and from "61 62 63 64" to "abcd" I manage to get the Ascii value in hex but don't know how to get it back Qstring StrData = "abcd"; Qstring HexStrData; for (int i = 0; i < StrData.length(); i++) { HexStrData.append(Qstring::number(StrData.at(i).unicode(), 16)); HexStrData.append(" "); } 回答1: To do the first conversion you can use the following method: