qstring

Qt 下快速读写Excel指南

陌路散爱 提交于 2019-12-16 11:17:23
Qt Windows 下快速读写Excel指南 很多人搜如何读写excel都会看到用 QAxObject 来进行操作,很多人试了之后都会发现一个问题,就是慢,非常缓慢!因此很多人得出结论是 QAxObject 读写excel方法不可取,效率低。 后来我曾试过用ODBC等数据库类型的接口进行读写,遇到中文嗝屁不说,超大的excel还是会读取速度慢。 最后,看了一些开源的代码后发现,Windows下读取excel,还是用 QAxObject 最快!没错,就是用 QAxObject 读写最快!!!(读取10万单元格229ms) 大家以后读取excel时(win下),不用考虑别的方法,用 QAxObject 就行,速度杠杠的,慢是你操作有误!下面就说说如何能提高其读取效率。 读取excel慢的原因 这里不说如何打开或生成excel,着重说说如何快速读取excel。 网上搜到用Qt操作excel的方法,读取都是使用类似下面这种方法进行: QVariant ExcelBase :: read ( int row , int col ) { QVariant ret ; if ( this - > sheet != NULL && ! this - > sheet - > isNull ( ) ) { QAxObject * range = this - > sheet - >

QT 票据打印系统

做~自己de王妃 提交于 2019-12-16 02:01:16
#include "charge.h" #include "ui_charge.h" #include<QMenuBar> #include <QMainWindow> #include<QWidget> #include <QPrintDialog> #include <QPrinter> #include <QPainter> #include <QStackedWidget> #include <QSqlQuery> #include<QMessageBox> #include <QSqlDatabase> #include <QDebug> #include <QSqlError> #include <QVariantList> #include <QSqlTableModel> #include<QDebug> #include <QFile> #include <QPdfWriter> #include <QFileDialog> #include <QSqlRecord> #include<QProcess> #include<iostream> #include <fstream> #include <windows.h> #include<QInputDialog> #include <QFileDevice> Charge::Charge(QWidget

Qt 5 中解决中文乱码的方法

走远了吗. 提交于 2019-12-16 00:45:23
在 Qt 4 的时代,解决中文乱码挺麻烦。要考虑用的是什么编译器,具体的可以参考下面这篇文章: http://blog.csdn.net/brave_heart_lxl/article/details/7186631 到了 Qt 5 的年代,这个问题变得简单了些。因为根据 Qt 的文档: http://doc.qt.io/qt-5.6/qstring.html#QString-7 中规定 QString 的 const char* 构造函数是调用 fromUtf8() 构造的。所以要求字符串字面量是 UTF-8 编码的字节。 这里先要解释一下下面两个概念: 源码字符集(the source character set):源码文件是使用何种编码保存的 执行字符集(the execution character set):可执行程序内保存的是何种编码(程序执行时内存中字符串编码) 源码字符集很容易理解,就是我们源代码的编码。为了我们的代码能够跨平台,源文件要保存为带 BOM 的 utf-8。 执行字符集就麻烦多了。比如我们下面的代码片段: QString str("我是中文"); 即使这个文件存为 utf-8 格式了,编译成 exe 文件时,编译器也可能对这个字符串常量进行转码,转为别的编码格式。 在 gcc 中,控制这个转码操作的命令行参数是: -fexec-charset

Qt5.12获取本机IP地址

老子叫甜甜 提交于 2019-12-15 01:03:14
最近在写有关Qt网络通信方面,下面是一个小模块,获取主机的IP地址。 QString get_local_ip ( ) { QHostInfo info = QHostInfo :: fromName ( QHostInfo :: localHostName ( ) ) ; // 找出一个IPv4地址即返回 foreach ( QHostAddress address , info . addresses ( ) ) { if ( address . protocol ( ) == QAbstractSocket :: IPv4Protocol ) { return address . toString ( ) ; } } return "0.0.0.0" ; } 首先获取本机所有IP地址信息,包括环回地址如127.0.0.1,以及本机地址如192.168.1.x等等,有安装虚拟机的还有其他地址等等。 /** * @brief 检测当前网卡是否是虚拟网卡(VMware/VirtualBox)或回环网卡 * @param str_card_name 网卡的描述信息 * @return 如果是虚拟网卡或回环网卡,返回true, 否则返回false */ bool is_virtual_network_card_or_loopback ( QString str_card_name )

QString to unicode std::string

孤人 提交于 2019-12-14 03:52:45
问题 I know there is plenty of information about converting QString to char* , but I still need some clarification in this question. Qt provides QTextCodec s to convert QString (which internally stores characters in unicode) to QByteArray , allowing me to retrieve char* which represents the string in some non-unicode encoding. But what should I do when I want to get a unicode QByteArray ? QTextCodec* codec = QTextCodec::codecForName("UTF-8"); QString qstr = codec->toUnicode("Юникод"); std::string

QT开发之QT5 connect新语法:Lambda表达式

江枫思渺然 提交于 2019-12-14 01:14:00
Qt 5 之前的语法 在 Qt 5 之前,我们需要使用下面的语句来链接 signal 和 slot: connect(sender, SIGNAL(valueChanged(QString, QString)), receiver, SLOT(updateValue(QString))); Qt 实际上利用 SIGNAL和SLOT这两个宏 ,把其后的函数名转换成一个字符串。随后,moc 将会扫描全部文件,将所有的 signal 和 slot 提取出来做成一个 映射表 。QObject::connect()函数则会从这个映射表里面找到该字符串,从 signal 的名字就可以找到 slot 的名字,因此也就知道了在 signal emit 的时候,该去调用哪一个 slot 函数。 Qt 5 之前的 signal/slot 语法的问题 从上面的解释可以看出,Qt 5 之前版本提供的这种语法其实有一些问题: 没有编译期检查 :因为函数名被处理成字符串,所有的检查都是在运行时完成的。这就是为什么有时会发生编译通过了,但 slot 并没有被调用。此时,你就应该去检查 console 的输出,看看有没有什么 warning 说明 connect 并没有成功。 因为处理的是字符串,所以 slot 中的类型名字必须用 signal 的完全一致,而且在头文件中的和实际 connect

QString to String and vica versa

拈花ヽ惹草 提交于 2019-12-13 04:37:16
问题 I am doing one project in which i have to use QT software. I have one qt variable like QString name_device; I am reading one .mat file using matIO library who has 1x3 Char variable with the similar name. Can anyone please tell me that how i can transfer mat's 1x3 Char variable into QString varaible? and also after transferring into QString, i will process it and after processing i want to again save it in .mat file for which i again need to do a transferring from QString to 1x3 Char. It will

How can I use my enum in QString.arg()?

纵然是瞬间 提交于 2019-12-12 18:27:28
问题 My enum is declared as Q_ENUM macro so it print the enum field's name when using with qDebug() (as I'm using QT 5.5) instead of its value. I'd like to do the same with QString().arg() so I declared that same enum with Q_DECLARE_METATYPE() macro but it didn't work either and give the below error. Code: qDebug() << QString("s = %1").arg(myClass::myEnum::ok); error: error: no matching function for call to 'QString::arg(myClass::myEnum)' How can I fix this? 回答1: Q_ENUM does not provide a direct

Display array content in a List Widget Qt C++

牧云@^-^@ 提交于 2019-12-12 17:20:38
问题 i want to display some of the content of my array in a List Widget (item based) with Qt and C++, i tried this, but it dosent work : QString exemple[2] = 'blablabla' ui->listWidgetResult->addItem(exemple[2].toStdString().c_str()); Thanks ! 回答1: This can't work: QString example[2] = 'blablabla' First, ' is for char values, not for strings. Second, you are declaring an array of two QStrings, but assign it to a C string. What you mean is perhaps this: QString example[2] = {"blabla", "blabla"};

Return a QString from a function - thread safe?

耗尽温柔 提交于 2019-12-12 15:00:57
问题 I'm new to Qt - but this may be a very basic c++ issue. I have a simple function that returns a QString: QString testclass::myfunc(int i) { QString result; switch (i) { case 1: result = "one"; break; case 2: result = "two"; break; } return result; } Is this safe? Does the c compiler ensure the return value stays in memory long enough to be used by the calling function? (Or does this risk memory corruption). If the latter, what is the right way to return a QString? (Does the result var have to