qstring

How to convert QString to int?

我怕爱的太早我们不能终老 提交于 2019-12-02 23:14:57
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" 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 was a straight forward answer to the specific question, with a strict assumption. However as noted by

Allocating words from a string separated by spaces to a variable? C++ [qt] [duplicate]

我们两清 提交于 2019-12-02 22:39:05
问题 This question already has answers here : How do I iterate over the words of a string? (76 answers) Closed 5 years ago . I just wanted to know what the technical term for allocating words from a string separated by spaces to a variable is called so I can look up a tutorial for it. Any terms, links, or explanations would be greatly appreciated. 回答1: You can do it like: QString lineText = "some sample words"; QStringList tokens= lineText.split(" ",QString::SkipEmptyParts); You can do whatever

C#调用C++(QT5.5.1项目)的C++/CLI(CLR项目)项目技术笔记

匿名 (未验证) 提交于 2019-12-02 22:06:11
导航                                                                                      1.编译环境 系统:windows10 环境:VS2010 + Qt5.5.1 2.项目配置 1.设置附加包含目录 1.此项设置包含的头文件,需要填入用到的.h文件目录 2.下图中的QTDIR是Qt5.5.1安装目录环境变量(默认路径:C:\Qt\Qt5.5.1\5.5\msvc2010) 2.设置附加库目录 1.此项设置引用的lib目录,如下图。 3.设置附加依赖项 1.此处设置指定的lib文件,一般不用填写。 3.CLR中各种定义 1.接口定义 2.类定义 3.枚举定义 4.属性定义 1.接口中定义: 4.CLR中各种使用 1.类的实例化 所有.net对象都需要使用gcnew进行创建,gcnew创建的对象不需要自己手动释放内存。 GTable ^ ret = gcnew GTable(); 2.命名空间的使用 命名空间用于限定类,不同于C#,这里使用::进行分割。 virtual MyNameSpace::ITable ^ GetTable(int index); 5.CLR中数据类型的转换 1.String ^ 到 QString 的转换 QString MarshalString(String ^ s

QSqlDatabase的进一步封装(多线程支持+更加简单的操作)――同时支持MySQL, SQL Server和Sqlite

匿名 (未验证) 提交于 2019-12-02 22:06:11
注:需要C++11的支持 .h #ifndef __JasonQt_Database_h__ #define __JasonQt_Database_h__ // C++ lib import #include <functional> // Qt lib import #include <QtCore> #include <QtSql> #define PropertyDeclare(Type, Name, setName, ...) \ private: \ Type m_ ## Name __VA_ARGS__; \ public: \ inline const Type &Name(void) const { return m_ ## Name; } \ inline void setName(const Type &Name) { m_ ## Name = Name; } \ private: namespace JasonQt_Database { enum DatabaseModeEnum{ DatabaseNameMode, DatabaseHostMode }; enum QueryMode { QueryAutoMode, QueryMultiMode, QuerySingleMode }; class DatabaseSettings { private:

QT在linux下获取网络类型

匿名 (未验证) 提交于 2019-12-02 21:59:42
开发中遇到这样一个需求,需要判断当前网络的类型(wifi或者4G或者网线),在这里给大家一块分享下: 1、这里有一个linux指令:nmcli(大家自行百度即可) 3、如何用QT去调取这个指令获取结果来进行上报呢?来一段代码吧 //执行linux指令获取返回结果 QString Common::executeLinuxCmd(QString strCmd) { QProcess p; p.start("bash", QStringList() <<"-c" << strCmd); p.waitForFinished(); QString strResult = p.readAllStandardOutput(); return strResult; } //获取网络状态码 int PLC::networkStatus() { QString strDevice = Common::executeLinuxCmd("nmcli device status"); QStringList listDevice = strDevice.split("\n"); QString strBin = ""; QString strWifi = "0"; QString str4G = "0"; QString strWired = "0"; foreach(QString tmpStr ,

qt tableview 鼠标移动显示QToolTip

我的梦境 提交于 2019-12-02 14:47:38
QAbstractItemView 模型视图框架,鼠标移动显示坐标数值 # include "widget.h" # include "ui_widget.h" # include <QtDebug> # include "tabledelegate.h" # include <QAbstractItemModel> # include <QToolTip> Widget : : Widget ( QWidget * parent ) : QWidget ( parent ) , ui ( new Ui : : Widget ) { ui -> setupUi ( this ) ; tableModel = new TableModel ( ) ; // Model ui -> tableView -> setModel ( tableModel ) ; // View ui -> tableView -> setItemDelegate ( new TableDelegate ) ; // Delegate ui -> tableView -> verticalHeader ( ) -> setDefaultSectionSize ( 20 ) ; ui -> tableView -> horizontalHeader ( ) -> setDefaultSectionSize (

Finding index of a cell containing a value and highlighting all those cells in QTableView

随声附和 提交于 2019-12-02 04:47:05
问题 How can we find out the index (i.e both row and column numbers) of a cell containing a QString in a QTableView using QT c++? (P.S.:Without clicking on the cell in qtableview) 回答1: You can use findItems() function to find your cell. findItems() function returns a list of items that match the given text, using the given flags, in the given column. for (int index = 0; index < model->columnCount(); index++) { QList<QStandardItem*> foundLst = model->findItems("YourText", Qt::MatchExactly, index);

Finding index of a cell containing a value and highlighting all those cells in QTableView

大城市里の小女人 提交于 2019-12-02 01:42:17
How can we find out the index (i.e both row and column numbers) of a cell containing a QString in a QTableView using QT c++? (P.S.:Without clicking on the cell in qtableview) You can use findItems() function to find your cell. findItems() function returns a list of items that match the given text, using the given flags, in the given column. for (int index = 0; index < model->columnCount(); index++) { QList<QStandardItem*> foundLst = model->findItems("YourText", Qt::MatchExactly, index); } If you want to get index of found item and highlight it use this code: for (int index = 0; index < model-

Why does pyqtSlot decorator cause “TypeError: connect() failed”?

血红的双手。 提交于 2019-12-02 01:13:17
问题 I have this Python 3.5.1 program with PyQt5 and a GUI created from a QtCreator ui file where the pyqtSlot decorator causes "TypeError: connect() failed between textChanged(QString) and edited()". In the sample code to reproduce the problem I have 2 custom classes: MainApp and LineEditHandler. MainApp instantiates the main GUI (from the file "mainwindow.ui") and LineEditHandler handles a QLineEdit object. LineEditHandler reason to exist is to concentrate the custom methods that relate mostly

Qt/C++ Convert QString to Decimal

限于喜欢 提交于 2019-12-01 21:34:33
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; } lpapp As per documentation : int QString::toInt(bool * ok = 0, int base = 10) const Returns the string converted to an int using base base , which is 10 by default and must