qstring

Operator << for QString

别来无恙 提交于 2019-12-23 06:57:08
问题 It makes sense to implement << for QString like: std::ostream& operator <<(std::ostream &stream,const QString &str) { stream << str.toAscii().constData(); //or: stream << str.toStdString(); //?? return stream; } instead of writing stream << str.toAscii().constData(); every time in the code. However, since it is not in standard Qt library, I'm assuming there is any particular reason not to do so. What are the risks/inconvenience of overloading << as specified above? 回答1: If the << operator is

Convert a multiline QString into a one line QString

ε祈祈猫儿з 提交于 2019-12-23 02:43:26
问题 I have something like this: void ReadFileAndConvert () { QFile File (Directory + "/here/we/go"); if(File.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream Stream (&File); QString Text; do { Text = Stream.readLine(); Text = Text.simplified(); // Here I want to convert the multiline QString Text into a oneline QString // ... } The QString Text consists of a multiline Text that I need to convert into a online Text/QString. How can I achieve this? greetings 回答1: Put your text into a

Qt Why use QString::number() over QLocale().toString()?

∥☆過路亽.° 提交于 2019-12-23 01:26:31
问题 The application I am working on will be launched in many countries and needs to support their language. I've been going back through my code and replacing every instance of: QString::number() and QString().toDouble() with QLocale().toString() and QLocale().toDouble() I haven't found much online comparing the two classes, but I am interested in the repercussions of using the latter, and if there are none - why ever use the QString functions? Essentially I just want to make sure I'm not harming

淘宝开放平台API调用nodejs实现

风格不统一 提交于 2019-12-21 23:08:29
最近开发淘宝开放平台上的应用,淘宝本身提供了php, c# ,java,python四中调用的方法和SDK,由于最近nodejs非常火热,所以我基于nodejs实现了一套调用的方式,具体实现细节如下 源代码地址: TOP-Nodejs-seed 淘宝开放平台 API调用Nodejs版本实现 淘宝开放平台(Taobao Open Platform以下简称TOP)API调用方式可以通过 此处 查看。 本代码为调用TOP API的Nodejs实现版本。可以在此基础上进行开发. 你可以通过如下的步骤,轻松进入开发状态 1,获得代码 https://github.com/mz121star/taobao.git 2,进入项目目录,执行如下命令安装项目的依赖包 npm install 3,修改appconfig.js文件中的Appkey和Appsecret的值(该值从你的应用证书页面获得) AppKey:"从淘宝获得的Appkey", AppSecret:"从淘宝获得的AppSecret" 到此为止 ,你已经完成了项目运行起来所需要的全部步骤,你可以通过如下命令启动web服务. node app.js 此时,你可以通过浏览器访问 http://localhost:3000 查看效果,本项目实现了一个简单的获取卖家当前出售商品的demo。至此,所有演示已经结束,你可以通过如下的介绍

Maximum size of QString

老子叫甜甜 提交于 2019-12-21 23:05:40
问题 I am using Qt 5.9 on Ubuntu 16.04 64-bit architecture. I had a requirement in which I need to take input from a file which can have characters in the range of 10^8. Unfortunately breaking down the file in parts and working on that is not an option as I need the entire data in the file for the operation of my code. From what I have thought out so far I plan to store the file data in a QString (any other suggestions are welcome). What is the maximum size that QString can store in this regard? I

How to write a QString on several lines?

若如初见. 提交于 2019-12-21 07:22:02
问题 Do you have a better way to do that ? QString str("I am a long long long" + QString("long long long") + QString("long QString") ); I don't like all this QString. 回答1: In C++ string literals are automatically concatenated when placed next to each other. QString str("I am a long long long" "long long long" "long QString"); 回答2: the QT way : #include <QString> QString myStr = QStringLiteral(""); Start typing, when you press return, he will auto add the " and open a new line starting with ". 来源:

How to write a QString on several lines?

戏子无情 提交于 2019-12-21 07:22:00
问题 Do you have a better way to do that ? QString str("I am a long long long" + QString("long long long") + QString("long QString") ); I don't like all this QString. 回答1: In C++ string literals are automatically concatenated when placed next to each other. QString str("I am a long long long" "long long long" "long QString"); 回答2: the QT way : #include <QString> QString myStr = QStringLiteral(""); Start typing, when you press return, he will auto add the " and open a new line starting with ". 来源:

QT信号槽机制

痞子三分冷 提交于 2019-12-20 18:04:43
信号槽 信号槽是QT中用于对象间通信的一种机制,也是QT的核心机制。在GUI编程中,我们经常需要在改变一个组件的同时,通知另一个组件做出响应。例如: 一开始我们的Find按钮是未激活的,用户输入要查找的内容后,查找按钮就被激活,这就是输入框与Find按钮这两个组件间通信的例子。 早期,对象间的通信采用回调来实现。回调实际上是利用函数指针来实现,当我们希望某件事发生时处理函数能够获得通知,就需要将回调函数的指针传递给处理函数,这样处理函数就会在合适的时候调用回调函数。回调有两个明显的缺点: 它们不是类型安全的,我们无法保证处理函数传递给回调函数的参数都是正确的。 回调函数和处理函数紧密耦合,源于处理函数必须知道哪一个函数被回调。 信号与槽 在QT中,我们有回调技术之外的选择,也即是信号槽机制。所谓的信号与槽,其实都是函数。当特定事件被触发时(如在输入框输入了字符)将发送一个信号,而与该信号建立的连接槽,则可以接收到该信号并做出反应(激活Find按钮)。 QT组件预定义了很多信号和槽,而在GUI编程中,我们习惯于继承那些组件,继承后添加我们自己的槽,以便以我们的方式来处理信号。槽和普通的C++成员函数几乎是一样的,它可以是虚函数,可以被重载,可以是共有、私有或是保护的,也同样可以被其他成员函数调用。它的函数参数也可以是任意类型的。唯一不同的是:槽还可以和信号连接在一起。 与回调不同

How to convert QString to int?

风流意气都作罢 提交于 2019-12-20 09:46:33
问题 I have a QString in my sources. So I need to convert it to integer without "Kb". I tried Abcd.toInt() but it does not work. QString Abcd = "123.5 Kb" 回答1: You don't have all digit characters in your string. So you have to split by space QString Abcd = "123.5 Kb"; Abcd.split(" ")[0].toInt(); //convert the first part to Int Abcd.split(" ")[0].toDouble(); //convert the first part to double Abcd.split(" ")[0].toFloat(); //convert the first part to float Update : I am updating an old answer. That

Qt/C++ Convert QString to Decimal

ε祈祈猫儿з 提交于 2019-12-20 02:29:29
问题 How Can I convert QString to decimal ? In C# code it look like that: public static decimal ConvertToDecimal(string tekst, bool upperOnly) { decimal num = 0m; decimal num2 = 1m; string text = upperOnly ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234"; int i = tekst.Length - 1; while (i >= 0) { num += text.IndexOf(tekst[i]) * num2; i--; num2 *= text.Length; } return num; } 回答1: As per documentation: int QString::toInt(bool * ok = 0, int base