qstring

python 的 string 和 PyQt 的 QString 的区别

时间秒杀一切 提交于 2019-11-29 04:44:27
以下在 Python2.6和PyQt4.4.4 for Python2,6环境下讨论: Python中有两种有关字符的类型:Python string object和Python Unicode object。主要使用Python string object进行数据输入输出。 PyQt中与之相对应的字符有关类型是:QByteArray和QString。主要使用QString操作数据。 1. Python和PyQt中的类型对应 注意是类型相似,不是相等。 需要先了解编码:ascii、gb2312、big5,这些是各国自己文字不同的编码;unicode,国际通用编码,就是穷尽这个世界上所有的文字,给 每个文字编一个,又分utf-8方案--最常使用的128个英文字母用一个字节来表示,而中文使用三个字节来表示,utf-16方案--其中英文和中文都 使用两个字节来表示,而其它字符采用四个字节,utf-32方案--所有的文字都用四个字节来表示。 unicode就可用来作为各种独立编码如ascii、gb2312、big5的转换中介。 Python中gkb == gb2312。 1)Python string object可以理解为一个接一个字节(byte,8位)的字节组,至于表示什么编码,与表示文字有关,如:"python string","中文"。注意它是有不同编码区分的!

How to get QString from QListView selected item in Qt?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 23:24:55
I need to get the selected item name in QListView as a QString . I have tried to google, but I haven't found anything useful. It depends on selectionMode lets say you have ExtendedSelection which means you can select any number of items (including 0). ui->listView->setSelectionMode(QAbstractItemView::ExtendedSelection); you should iterate through ui->listView->selectionModel()->selectedIndexes() to find indexes of selected items, and then call text() method to get item texts: QStringList list; foreach(const QModelIndex &index, ui->listView->selectionModel()->selectedIndexes()) list.append

Convert an int to a QString with zero padding (leading zeroes)

十年热恋 提交于 2019-11-28 21:47:32
问题 I want to "stringify" a number and add zero-padding, like how printf("%05d") would add leading zeros if the number is less than 5 digits. 回答1: Use this: QString number = QString("%1").arg(yourNumber, 5, 10, QChar('0')); 5 here corresponds to 5 in printf("%05d") . 10 is the radix, you can put 16 to print the number in hex. 回答2: QString QString::rightJustified ( int width, QChar fill = QLatin1Char( ' ' ), bool truncate = false ) const int myNumber = 99; QString result; result = QString::number

How to deal with “%1” in the argument of QString::arg()?

天大地大妈咪最大 提交于 2019-11-28 21:18:49
Everybody loves QString("Put something here %1 and here %2") .arg(replacement1) .arg(replacement2); but things get itchy as soon as you have the faintest chance that replacement1 actually contains %1 or even %2 anywhere. Then, the second QString::arg() will replace only the re-introduced %1 or both %2 occurrences. Anyway, you won't get the literal "%1" that you probably intended. Is there any standard trick to overcome this? If you need an example to play with, take this #include <QCoreApplication> #include <QDebug> int main() { qDebug() << QString("%1-%2").arg("%1").arg("foo"); return 0; }

Qt的容器类

孤人 提交于 2019-11-28 19:48:53
Qt提供了多种容器类,这些容器可以用于存储指定类型的数据项,并且可以实现对字符串列表的添加,存储,删除等操作。 容器类是基础模板的类,如常用的容器类 QList <T> ,T是一个具体的类型,可以是int,float等简单类型,也可以是QString,QDate等类,但不可以是QObject或任何其子类。T必须是一个可赋值的类型。 例如用 QList <T> 定义一个字符串列表的容器,其定义方法是: QList <QString> strList; 这样定义了一个QList容器类的变量strList,它的数据项是QString,所以strList可以用于处理字符串列表,例如: strList.append("one"); strList.append("two"); strList.append("three"); QString str = strList[0]; //str = "one" Qt的容器类大致分为 顺序容器 和 关联容器 。 顺序容器类 Qt的顺序容器类有QList,QLinkedList,QVector,QStack和QQueue。 QList QList是最常用的容器类,虽然它是以数组列表的形式实现的,但是在其前后添加数据非常快,QList以下标索引的方式对数据项进行访问。 QList用于添加,插入,替换,移动,删除数据项的函数有:insert()

qt--QWebEngine加载高德地图

扶醉桌前 提交于 2019-11-28 19:48:41
一、js与c++交互 首先在所创建项目的.pro配置中添加webenginewidgets模块 QT += webenginewidgets 然后在主窗口初始化时创建QWebEngineView对象 m_webView = new QWebEngineView(this); QStackedLayout* layout = new QStackedLayout(ui->frame); ui->frame->setLayout(layout); layout->addWidget(m_webView); 页面的加载和刷新 m_webView->load(url); m_webView->reload(); 辅助类JsContext //jscontext.h #ifndef JSCONTEXT_H #define JSCONTEXT_H #include <QObject> #include <QWebEnginePage> class JsContext : public QObject { Q_OBJECT public: explicit JsContext(QObject *parent = nullptr); signals: void recvdMsg(const QString& msg); //向mainwindow传递消息 public: // 向页面发送消息

Get plain text from QLineEdit

邮差的信 提交于 2019-11-28 14:11:14
I want to retrieve plain text from QLineEdit() object. The text method returns a QString object. I just want a simple string object. I am using pyqt4. def n(self): new_label=QLineEdit() new_label.setText("txt") txt=self.new_label.text() self.name=txt txt should be a simple string not QString . To convert one QString in Python 2 , do this: self.name = unicode(self.new_label.text()) To automatically convert all QStrings, put this at the beginning of your code: import sip sip.setapi('QString', 2) # must be before any pyqt imports from PyQt4 import QtCore, QtGui If you do this, there's no need to

Linux-Qt使用QThread多线程isRunning标志量问题

[亡魂溺海] 提交于 2019-11-28 10:42:16
---恢复内容开始--- 摘要 Qt帮助文档中是这样介绍的: bool QThread::isRunning () const Returns true if the thread is running; otherwise returns false. See also isFinished(). 解释的一本正经,使用却不然。 问题: 使用 QThread :: isRunning 标志量判断线程是否关闭时,判断出错,线程明明关闭, isRunning 仍然显示 true 解决方式: 使用 isRunning 和 isFinished 双标志量判断 程序说明: 界面程序(Display_PlayBack) 负责显示数据, 数据库读取线程(Thread_PlayBack) 负责一直读取数据库。 界面程序创建的数据库线程,也负责回收其空间。 程序中的代码: Thread_PlayBack.cpp void Thread_PlayBack::run()//一直读取数据库数据入缓存 { int rowNum,columnNum,fieldNo_longitude,fieldNo_latitude; double x,y,scale; SqlData data; QString str = QString::fromUtf8("SELECT 经度,纬度 FROM HT_12 WHERE

Draw rich text with QPainter

最后都变了- 提交于 2019-11-28 08:30:00
is there a way to draw fixed text that has subscripts. My goal is to have something like: "K_max=K_2 . 3" QString equation="K_max=K_2 . 3"; painter.drawText( QRect(x, y , width, y+height), Qt::AlignLeft|Qt::AlignVCenter, equation); I also tried formatting the text using html tags but it didn't help (tags got printed with the text): QString equation="<p>K<sub>max</sub></p>=<p>K<sub>2</sub></p>.3" Here is a full example using rich text of QTextDocument. mainWindow.cpp: #include "mainWindow.h" void MainWindow::paintEvent(QPaintEvent*) { QPainter painter(this); QTextDocument td; td.setHtml("K<sub