qstring

What is the equivalence for QString::arg() in QML

邮差的信 提交于 2019-12-10 00:45:51
问题 I'm wondering How I can have a string in QML that will be occupied with some arguments? Some thing like this in Qt: QString str("%1 %2"); str = str.arg("Number").arg(12);//str = "Number 12" 回答1: In QML environment, the arg() function already added to the string prototype, so basically you can use the string.arg() in QML just like C++. There is less documentation about this, but I'm sure it works in Qt 4.7 + QtQuick 1.1 Take at look at the Qt 5 doc : http://qt-project.org/doc/qt-5.0/qtqml/qml

QT学习之深入了解信号槽

我怕爱的太早我们不能终老 提交于 2019-12-09 19:35:04
槽函数和普通的 C++成员函数没有很大的区别。它们也可以使 virtual 的;可以被重写;可以使 public、protected 或者 private 的;可以由其它的 C++函数调用;参数可以是任何 类型的。如果要说区别,那就是,槽函数可以和一个信号相连接,当这个信号发生时,它可以被自动调用。(来自QT学习之路) connect()语句原型  connect(sender, SIGNAL(signal), receiver, SLOT(slot)); sender 和 receiver 都是 QObject 类型的,singal 和 slot 都是没有参数名称的函数签名。SINGAL()和 SLOT()宏用于把参数转换成字符串。 一个信号也可以与多个槽连接 connect(slider, SIGNAL(valueChanged(int)),spinBox, SLOT(setValue(int))); connect(slider, SIGNAL(valueChanged(int)),this, SLOT(updateStatusBarIndicator(int))); 这时候,槽会被一个一个调用,但是顺序是不确定的。 多个信号也可以连到一个槽 只要任意一个信号发出,槽就会被调用 一个信号也可以连接到另外一个信号 connect(lineEdit, SIGNAL

Qt string builder in for loop

匆匆过客 提交于 2019-12-08 16:23:32
问题 following this and this documentation I would use the QStringBuilder in a for loop. The code where I should apply it is QStringList words; QString testString; for (auto it = words.constBegin(); it != words.constEnd(); ++it) { testString += "[" + *it + "] "; } However I don't understand how I could write it to use the QStringBuilder as here I'm doing an assignment, instead the QStringBuilder requires me to use the % operator and do only one assignment following the docs. 回答1: AFAICS here,

superscript for QTableWidget header

爱⌒轻易说出口 提交于 2019-12-08 05:34:18
问题 I'm learning QT and have to design a table like this I need "m2" with "2" as superscript. Here is my code: ui.tableWidget->horizontalHeaderItem(0)->setText("Date"); ui.tableWidget->horizontalHeaderItem(0)->setBackgroundColor(QColor(217, 217, 217)); ui.tableWidget->horizontalHeaderItem(1)->setText("House address"); ui.tableWidget->horizontalHeaderItem(1)->setBackgroundColor(QColor(217, 217, 217)); ui.tableWidget->horizontalHeaderItem(2)->setText("Area \n [m\u00B2]"); ui.tableWidget-

How can I convert QByteArray to string in Qt 5.3?

自作多情 提交于 2019-12-08 01:36:15
问题 I am using some functions to convert QVector's to QByteArray's , for example: QByteArray Serialize::serialize(QVector<double> data) { QByteArray byteArray; QDataStream out(&byteArray, QIODevice::WriteOnly); out << data; return byteArray; } void Serialize::deserialize(QByteArray byteArray, QVector<double> *data) { QDataStream in(&byteArray, QIODevice::ReadOnly); in >> *data; } Now, that I have the QByteArray I need to put it in a text file, how can I convert it to QString ? I already tried the

superscript for QTableWidget header

浪尽此生 提交于 2019-12-07 11:16:23
I'm learning QT and have to design a table like this I need "m2" with "2" as superscript. Here is my code: ui.tableWidget->horizontalHeaderItem(0)->setText("Date"); ui.tableWidget->horizontalHeaderItem(0)->setBackgroundColor(QColor(217, 217, 217)); ui.tableWidget->horizontalHeaderItem(1)->setText("House address"); ui.tableWidget->horizontalHeaderItem(1)->setBackgroundColor(QColor(217, 217, 217)); ui.tableWidget->horizontalHeaderItem(2)->setText("Area \n [m\u00B2]"); ui.tableWidget->horizontalHeaderItem(2)->setBackgroundColor(QColor(217, 217, 217)); ui.tableWidget->horizontalHeaderItem(3)-

Convert a multiline QString into a one line QString

百般思念 提交于 2019-12-07 05:54:24
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 Put your text into a QStringList , and use QStringList::join() , e.g. QStringList doc; [...] Text = Stream.readLine(); Text = Text

Strange Qt Code with strings

為{幸葍}努か 提交于 2019-12-06 21:21:42
问题 I found my friend's Qt code and he uses the modulo operator on two QString s like this: QString result = oneString % twoString; What does it mean? 回答1: It's just another (more efficient) way to concatenate QString s as described in the manual QStringBuilder uses expression templates and reimplements the '%' operator so that when you use '%' for string concatenation instead of '+', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString.

ImportError: cannot import name 'QStringList' in PyQt5

ぃ、小莉子 提交于 2019-12-06 18:19:49
问题 I am using PyQt5 but can't import QStringList. I know that QStringList used to be in the module QtCore in PyQt4. So I try importing the class using from PyQt5.QtCore import QStringList but it shows this error C:\Python34\python.exe C:/Users/User/PycharmProjects/FirstProject/Test.py Traceback (most recent call last): File "C:/Users/User/PycharmProjects/FirstProject/Test.py", line 3, in <module> from PyQt5.QtCore import QStringList ImportError: cannot import name 'QStringList' I am using

QT获取linux下的当年用户名

南笙酒味 提交于 2019-12-06 14:21:08
故事背景:客户端启动的时候需要加载机器/home/xx/test.jpg的图片作为背景图,但是有的机器用户名叫AAA,有的机器名叫BBB,所以我需要获取当前用户的home目录 技术调研: QStandardPaths QString strImagePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/justtake.jpg"; QFile file(strImagePath); if(file.exists()) { this->setStyleSheet(QString("#firstWidget{border-image:url(%1)}").arg(strImagePath)); }else { this->setStyleSheet("background-color:white"); } 大家可以根据自己的业务需求进行扩展,评论区随时交流。 来源: https://www.cnblogs.com/xupeidong/p/11989455.html