qstring

Sort filenames naturally with Qt

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am reading a directories content using QDir::entryList() . The filenames within are structured like this: index_randomNumber . png I need them sorted by index , the way the Windows Explorer would sort the files so that I get 0_0815.png 1_4711.png 2_2063.png ... instead of what the sorting by QDir::Name gives me: 0_0815.png 10000 _6661 . png 10001 _7401 . png ... Is there a built-in way in Qt to achieve this and if not, what's the right place to implement it? 回答1: If you want to use QCollator to sort entries from the list of

How to take ScreenShot Qt/QML

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: QtQuick1 example I can’t make it work on QtQuick2 screenCapture.hpp #include <QObject> class QString; class QQuickView; class screenCapture : public QObject { Q_OBJECT public: explicit screenCapture(QQuickView *parent = 0); public slots: void capture(QString const &path) const; private: QQuickView *currentView_; }; screenCapture.cpp #include <QPixmap> #include <QQuickView> #include <QString> #include "screenCapture.hpp" screenCapture::screenCapture(QQuickView *currentView) : QObject(0), currentView_(currentView) { } void screenCapture:

How to keep the source signal's parameters while using QSignalMapper?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I ran into a problem that I need to keep the mapped source signal's parameters. So far I only found examples to map signals without any parameter. For example, the clicked() signal: signalMapper = new QSignalMapper ( this ); signalMapper -> setMapping ( taxFileButton , QString ( "taxfile.txt" )); connect ( taxFileButton , SIGNAL ( clicked ()), signalMapper , SLOT ( map ())); connect ( signalMapper , SIGNAL ( mapped ( QString )), this , SLOT ( readFile ( QString ))); However, I would need to map some signal with its own parameters,

AttributeError: 'QString' object has no attribute 'rfind'

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: My application runs fine in one computer but when I run the same application in another I get the error: Traceback ( most recent call last ): File "./th.py" , line 98 , in browse_file2 self . textEdit_2 . append ( str ( os . path . basename ( p ))) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py" , line 121 , in basename i = p . rfind ( '/' ) + 1 AttributeError : 'QString' object has no attribute 'rfind' I have seen a similar error here . According to this, I need to typecast parameter to 'QString

QNetworkAccessManager one instance and connecting slots

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have my first Qt application in development. It's a desktop client for site messaging. Qt documentation says that i need to have only one instance of QNetworkAccessManager accross application. But i also read that using of singletons with Qt isn't a good idea. How i can make one instance of QNetworkAccessManager across app? Another question is how to properly connect slots while i call ApiHandler functions from other classes? For example i have ExampleApi class which uses functions of ApiHandler , in updateMessageList slot

zipping a folder/file using qt

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i would like to know if we have any class in qt which can zip a folder or file.i used qprocess to compress,it got compressed but i am unable to uncompress it using normal zip tool.can anyone let me know how can we compress a folder/file using qt api classes 回答1: A few years ago I had such a issue, and here is my solution: 1). get QuaZip (here is the link text ) 2). include quazip sources to your project file Headers: HEADERS += src/quazip/crypt.h \ src/quazip/ioapi.h \ src/quazip/quazip.h \ src/quazip/quazipfile.h \ src/quazip/quazipfileinfo

Qt parsing JSON using QJsonDocument, QJsonObject, QJsonArray

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm using Qt5. I am trying to obtain values from a json object. Here is what the json object looks like that I am trying to get data from: { "success" : true , "properties" : [ { "ID" : 1001 , "PropertyName" : "McDonalds" , "key" : "00112233445566778899aabbccddeeff" }, { "ID" : 1002 , "PropertyName" : "Burger King" , "key" : "10112233445566778899aabbccddeeff" }, { "ID" : 1003 , "PropertyName" : "Taco Bell" , "key" : "20112233445566778899aabbccddeeff" } ] } How can I create three arrays that contain properties[x].ID, properties[x]

2.1、QString――字符串类

匿名 (未验证) 提交于 2019-12-03 00:38:01
1.QString重载了+,+=运算符,跟c++中string一样。 2. QString::append(QString)函数,这个函数将参数连接到this后面,跟python有点像。 QString str = "hello " ; str .append( "world" ); //str="hello world" 3.QString::sprintf();这个函数跟c++中的也是一样的 文章来源: 2.1、QString――字符串类

基于Qt5 的串口助手

匿名 (未验证) 提交于 2019-12-03 00:37:01
概述 由于前段时间有个项目用需要一个上位机与单片机进行实现串口通讯,所以参考网上的教程用qt5完成了上位机的设计,目前实现了基本的功能,其他的功能还在完善中 首先要注意的是:因为应用到了qt5自带的串口通信模块,所以在项目的.pro文件中加入一句 QT += serialport,并在头文件中加入包含文件 #include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPortInfo> 以下是mainwindow.h的内容 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPortInfo> #include <QLabel> #include <QTimer> #include <windows.h> #include <QString> #include <dbt.h> #include <QDebug> #include<devguid.h> #include<SetupAPI.h> #include<InitGuid.h> namespace Ui { class MainWindow; }

Qt学习之正则表达式

匿名 (未验证) 提交于 2019-12-03 00:34:01
许多同学告诉我qt中正则表达式是一个很强大的类QRegExp,所以我通过网上的博客和各种资料以及课本对正则表达式进行了学习各种博客上的内容都很好,但是都不是很全面。所以我本文是对其他人文章的总结。以及自己的一些思考和看法,和学习到的知识点。如何使用这个类。 在项目中我们经常会遇到对字符串进行操作的情况,可以直接使用QString的一些函数,在这里QT提供了了一个类――QRegExp,使用正则表达式来操作字符串。学习一个事物最好的方式是从理论入手,了解清楚之后再去面向实例加以实践。最后将我们的知识掌握下来,就可以说是一次较为成功的学习了。 基本介绍知识 正则表达式(Regular Expression,通常简写为RegExp、RE等),预先定义一些字符或字符的组合,用于匹配文本中的一段字符串。 QRegExp是Qt的正则表达式类,Qt中有两个不同类的正则表达式。第一类为元字符,它表示一个或多个常量表达式;另一类为转义字符,它代表一个特殊字符。 一.元字符 ^ 匹配字符串首,例如, ^12可能是123,但不能是312 [] 匹配括号内输入的任意字符,[123]可以为1, 2 或3 + 匹配至少一个前导字符,例如, 1+2必须为一个或多个1, 后跟一个2 二.统配模式 通过 QRegExp::setPatternSyntax(QRegExp::Wildcard)