这篇文章主要讲解了“Qt类库怎么使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Qt类库怎么使用”吧!
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、做网站、双江网络推广、微信平台小程序开发、双江网络营销、双江企业策划、双江品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供双江建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
//int转字节数组 static QByteArray intToByte(int i); static QByteArray intToByteRec(int i); //字节数组转int static int byteToInt(const QByteArray &data); static int byteToIntRec(const QByteArray &data); static quint32 byteToUInt(const QByteArray &data); static quint32 byteToUIntRec(const QByteArray &data); //ushort转字节数组 static QByteArray ushortToByte(ushort i); static QByteArray ushortToByteRec(ushort i); //字节数组转ushort static int byteToUShort(const QByteArray &data); static int byteToUShortRec(const QByteArray &data);
QByteArray QUIHelper::intToByte(int i) { QByteArray result; result.resize(4); result[3] = (uchar)(0x000000ff & i); result[2] = (uchar)((0x0000ff00 & i) >> 8); result[1] = (uchar)((0x00ff0000 & i) >> 16); result[0] = (uchar)((0xff000000 & i) >> 24); return result; } QByteArray QUIHelper::intToByteRec(int i) { QByteArray result; result.resize(4); result[0] = (uchar)(0x000000ff & i); result[1] = (uchar)((0x0000ff00 & i) >> 8); result[2] = (uchar)((0x00ff0000 & i) >> 16); result[3] = (uchar)((0xff000000 & i) >> 24); return result; } int QUIHelper::byteToInt(const QByteArray &data) { int i = data.at(3) & 0x000000ff; i |= ((data.at(2) << 8) & 0x0000ff00); i |= ((data.at(1) << 16) & 0x00ff0000); i |= ((data.at(0) << 24) & 0xff000000); return i; } int QUIHelper::byteToIntRec(const QByteArray &data) { int i = data.at(0) & 0x000000ff; i |= ((data.at(1) << 8) & 0x0000ff00); i |= ((data.at(2) << 16) & 0x00ff0000); i |= ((data.at(3) << 24) & 0xff000000); return i; } quint32 QUIHelper::byteToUInt(const QByteArray &data) { quint32 i = data.at(3) & 0x000000ff; i |= ((data.at(2) << 8) & 0x0000ff00); i |= ((data.at(1) << 16) & 0x00ff0000); i |= ((data.at(0) << 24) & 0xff000000); return i; } quint32 QUIHelper::byteToUIntRec(const QByteArray &data) { quint32 i = data.at(0) & 0x000000ff; i |= ((data.at(1) << 8) & 0x0000ff00); i |= ((data.at(2) << 16) & 0x00ff0000); i |= ((data.at(3) << 24) & 0xff000000); return i; } QByteArray QUIHelper::ushortToByte(ushort i) { QByteArray result; result.resize(2); result[1] = (uchar)(0x000000ff & i); result[0] = (uchar)((0x0000ff00 & i) >> 8); return result; } QByteArray QUIHelper::ushortToByteRec(ushort i) { QByteArray result; result.resize(2); result[0] = (uchar)(0x000000ff & i); result[1] = (uchar)((0x0000ff00 & i) >> 8); return result; } int QUIHelper::byteToUShort(const QByteArray &data) { int i = data.at(1) & 0x000000FF; i |= ((data.at(0) << 8) & 0x0000FF00); if (i >= 32768) { i = i - 65536; } return i; } int QUIHelper::byteToUShortRec(const QByteArray &data) { int i = data.at(0) & 0x000000FF; i |= ((data.at(1) << 8) & 0x0000FF00); if (i >= 32768) { i = i - 65536; } return i; }
感谢各位的阅读,以上就是“Qt类库怎么使用”的内容了,经过本文的学习后,相信大家对Qt类库怎么使用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!