-
8/16进制QString转换成int类,
int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const
If base is 0, the C language convention is used: If the string begins with “0x”, base 16 is used; if the string begins with “0”, base 8 is used; otherwise, base 10 is used.所以在toInt时只要把base设为0,直接使用c格式的类型转换就行了.“0x11”=“021”=“17”
-
QString 转换为char* ,const char* , char
char *QByteArray::data()
看示例如下:
QString tmp = “test”;
QByteArray text = tmp.toLocal8Bit();
char *data = new char[text.size() + 1];
strcpy(data, text.data());
delete [] data;
所以只需先转换成QByteArray类型再用data()方法就行,转换成char型,只要QByteArray.at(0)就行,变化很多不只这种. -
int ,float ,double to Qstring
QString::setNum(T a,int base)
QString QString::arg(T a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ’ ’ )) const -
QImage获取像素首址 uchar* 类型
uchar *QImage::bits()
Returns a pointer to the first pixel data. This is equivalent to scanLine(0). -
重载函数信号的类型指明,多用于信号槽连接
1.static_cast<T*>(a)
2.qOverload<T*>(a)
,5.7以后可用
eg:#if ( QT_VERSION >= QT_VERSION_CHECK(5,7,0) ) connect(input, QOverload<const QString &>::of(&QComboBox::activated) \ ,[&](const QString text){ //todo }); #else connect(input, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated)\ ,[&](const QString text){ //todo }); #endif
qt 类型转换相关
最新推荐文章于 2024-05-31 19:01:33 发布