Qt常用代码片段(2017.6.17更新)

6 篇文章 0 订阅
1.Returns the directory that contains the application executable.
[static] QString QCoreApplication::applicationDirPath()

qApp->applicationDirPath();

2.Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.
On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32".
The returned string may be the same as the argument on some operating systems, for example on Unix.
This function was introduced in Qt 4.2.
[static] QString QDir::toNativeSeparators(const QString &pathName)

QString path = QApplication::applicationDirPath() + "/" + "24rgb.bmp";
path = QDir::toNativeSeparators(path);

3.Returns a copy of the image in the given format(图像格式转换).
QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags = Qt::AutoColor) const

4.获取文件路径的绝对路径
QString QFileInfo::absolutePath() const
QFileInfo file("C:\\Program Files\\Microsoft SQL Server\\80\\COM\\sqlvdi.dll");
QString absolutePath = file.absolutePath(); // "C:/Program Files/Microsoft SQL Server/80/COM" 

5.显示非模态对话框,阻塞后面的调用,直到该非模态对话框关闭
QDialog dlg;
dlg.show();
QEventLoop loop;
connect(&dlg, SIGNAL(finished(int)), &loop, SLOT(quit()));
loop.exec(QEventLoop::ExcludeUserInputEvents);//loop.exec(),不排除用户输入事件
http://blog.csdn.net/cocoasprite/article/details/54631692
6.测量运行时间:QElapsedTimer与QTime
a.QElapsedTimer可以获得纳秒级时间间隔;
b.QTime可以获得毫秒级时间间隔。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值