【QT】QT问题集合

1、C++ 、Qt计算时间的方法
参考链接:https://www.cnblogs.com/m-zhang-yang/p/9449017.html
https://blog.csdn.net/chy555chy/article/details/53405072

timeGetTime的精度为ms级,必须添加Winmm.lib, 否则编译报错undefined reference;
timeGetTime可以使用GetTickCount代替(RTKLIB)

2、QT递归删除文件或者文件夹

bool MainWindow::DeleteFileOrFolder( const QString& strPath )
{
    if( strPath.isEmpty() || !QDir().exists( strPath ) )
        return false;

    QFileInfo fileInfo( strPath );

    if( fileInfo.isFile() )
        QFile::remove( strPath );
    else if( fileInfo.isDir() )
    {
        QDir qDir( strPath );
        qDir.setFilter( QDir::AllEntries | QDir::NoDotAndDotDot );
        QFileInfoList fileInfoLst = qDir.entryInfoList();
        foreach( QFileInfo qFileInfo, fileInfoLst )
        {
            if( qFileInfo.isFile() )
                qDir.remove( qFileInfo.absoluteFilePath() );
            else
            {
                DeleteFileOrFolder( qFileInfo.absoluteFilePath() );
                qDir.rmdir( qFileInfo.absoluteFilePath() );
            }
        }
        qDir.rmdir( fileInfo.absoluteFilePath() );
    }

    return true;
}

QTextStream

在使用QTextStream类的setFieldWidth函数设置占用宽度的时候切记endl也要占用字符宽度。
例如QTextStream::setFieldWidth(3)那么QTextStream<<endl就会产生一个换行符和两个空格占位。
导致下一行多出来两个空格。(切记)
所以QTextStream<<endl代码之前一定要QTextStream::setFieldWidth(1)

error: [Makefile.Debug:384: debug/RTMG_APPS_resource_res.o] Error 1

可能是你使用setWindowIcon(QIcon("widget.ico")); 没有找到ICO看看compile 输出就知道了。

Sock

http://keep.01ue.com/?pi=417481&_a=app&_c=index&_m=p
https://www.cnblogs.com/lic02891/archive/2012/11/09/2763210.html
https://www.cnblogs.com/sky-heaven/p/6840693.html

QProcess

参考链接
1、https://www.cnblogs.com/Romi/archive/2012/05/03/2480374.html

脱离进程开启exe使用下面代码:

QProcess::startDetached("E:\\Qt\\qtcreator-2.4.1\\bin\\qtcreator.exe",QStringList());

其中QStringList()参数必须传入,因为有时候带空格路径需要传入这个参数。

QT常见错误:“multiple definition of xxx”

打开QT工程文件*.pro
查看.pro 下面的SOURCES 和 HEADERS是否有重复的源文件名或头文件名,删掉重复即可。

QString 转Char *

比较好用的转换方法如下:

QString StringData = satObsTypeVctList.at(i);
const char *obs = StringData.toStdString().c_str();
char *a_ch = "hello world";
QString a_str = QString(a_ch) ;
QString a_str(a_ch) ;
  • 下图的错误说明QCmpBNCPro类没有为空的构造函数,而不是QPPPModel的错误:
    在这里插入图片描述

RTTI symbol not found for class ‘QObject’

1、出现原因: 在调用deleteLater() 后,调试执行到析构函数中 报错
解决方法: 问题出在:调用了两次析构函数,接下来,你应该有解决方向了吧。

Qt undefined reference to vtable for

参考链接:https://blog.csdn.net/chenlong12580/article/details/7431104

如果你手动添加了Q_OBJECT,请在Qt Creator的Build->Clean All菜单,然后手动删除build-×××文件夹下的Makefile文件。再重新编译

Qt再Ubuntu环境安装WebEigen

# install webengine in Ubuntu or centos etc. (amd64)
sudo apt-get update
sudo apt-get upgrade

sudo apt-get install libqt5webenginewidgets5
sudo apt-get install libqt5webenginecore5
sudo apt-get install libqt5webengine5
sudo apt-get install qtwebengine5-dev
sudo apt --fix-broken install

sudo ln -sf /usr/bin/x86_64-linux-gnu-ld.gold /usr/bin/ld

Ubuntu下增加自定义动态库目录

https://blog.csdn.net/cainiao2013/article/details/88926106

把动态链接库所在的路径添加到/etc/ld.so.conf中
sudo gedit /etc/ld.so.conf
更改成如下形式:

include /etc/ld.so.conf.d/*.conf
/home/david/MySoft/libraySelf/

然后更新/etc/so.cache

sudo ldconfig

QT 使用静态库或者动态库

https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肖恭伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值