0
我想轉換QString時,short.when我試試這個代碼QString時,使用短toShort
ui->lineEdit->text().toShort();
它非常適合於文本= 20,但它返回「0」值= 20.5。
但我需要值= 20.我該如何解決它?
我想轉換QString時,short.when我試試這個代碼QString時,使用短toShort
ui->lineEdit->text().toShort();
它非常適合於文本= 20,但它返回「0」值= 20.5。
但我需要值= 20.我該如何解決它?
返回0的原因是因爲小數點對於short
數據類型是無效字符。
如果你想能夠浮點數從QString
轉換爲整數,您需要將您的文本轉換爲float
或double
第一,然後用正常的四捨五入/截斷轉換爲short
。
使用該皈依字符串:
ui->lineEdit->text()->split(".")[0].toShort(0,10);
不允許在lineEdit –
的QString ::數小數點(。用戶界面 - > lineEdit->文本()toInt())toShort(); – Shf
我試過這段代碼,但仍有問題 inline __int16 GetInteger16FromStatic(QLineEdit * lineEdit) { \t QString text; \t __int16 nValue = 0; \t nValue = QString :: number(lineEdit-> text()。toDouble())。toShort(); \t \t \t return nValue; } – citi