qstring

How to make a QString from a QTextStream?

守給你的承諾、 提交于 2019-12-05 05:23:06
Will this work? QString bozo; QFile filevar("sometextfile.txt"); QTextStream in(&filevar); while(!in.atEnd()) { QString line = in.readLine(); bozo = bozo + line; } filevar.close(); Will bozo be the entirety of sometextfile.txt? dtech Why even read line by line? You could optimize it a little more and reduce unnecessary re-allocations of the string as you add lines to it: QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); QString text; text = in.readAll(); file.close(); As ddriver mentions, you should first open the file using file.open(…

QString与LPCWSTR 带中文的相互转换

微笑、不失礼 提交于 2019-12-05 04:39:09
Windosw 编程中,LPCWSTR 变量和QT中最常用到QString相互转换: 1.把 LPWSTR 转换成QString LPCWSTR str; QString :: fromStdWString(str); EG: LPCWSTR lpcwStr; QString str = QString::fromStdWString(lpcwStr); 2.把QString 转换成 LPWSTR QString :: toStdWString(); EG: QString args = QString ::fromLocal8Bit("汉字2ABC"); std: :wstring wlpstrstd = args.toStdWString(); LPCWSTR lpcwStr = wlpstrstd.c_str(); 来源: https://www.cnblogs.com/acmexyz/p/11906496.html

Using both std::string and QString interchangeably

落爺英雄遲暮 提交于 2019-12-05 02:32:47
I use Qt extensively in a software system I'm working on for graphical and GUI components. However, for most internal algorithms and processing of data Qt plays a smaller role. I'll often run into the need to convert from std::string to QString or visa versa. My inclination is to use std::string as much as possible and use QString only when I need to pass strings to Qt classes like those that work with the file system. As I was programming this morning, it hit me that it may be bad design to have both std::string and QString sprinkled throughout my code. Should I completely switch to QString?

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

给你一囗甜甜゛ 提交于 2019-12-04 22:37:37
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" Dickson 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-string.html just use : "foo%1".arg("bar"); Arguments are totally unnecessary in this example. In JS,

Qt——《开发指南》samp4.1源码分析

给你一囗甜甜゛ 提交于 2019-12-04 21:56:08
界面: 功能: 输入单价和数量,计算总价;进制转换 控件: Qlabel QLineEdit QPushButton 依赖关系图: main.cpp:程序入口 widget.h:窗体类头文件,定义了widget类 widget.cpp:widget类的功能实现 widget.ui:UI设计器生成的程序界面,存储了窗体上各组件的属性,设置,布局,信号——槽关联等 ui_widget.h:由widget.ui编译而成 箭头上的数字表示指向的对象在该文件中出现的次数,反应了文件之间的调用和依赖关系 文件调用图: 红色方框代表代码文件,蓝色方框代表头定义文件,灰色八边形框是Qt自带的类 函数调用图: UML图: 上面是方法,下面是属性 +是公有,-是私有 源码: main.cpp 1 #include "widget.h" 2 #include <QApplication> 3 4 int main(int argc, char *argv[]) 5 { 6 QApplication a(argc, argv); 7 Widget w; 8 w.show(); 9 10 return a.exec(); 11 } widget.h 1 #ifndef WIDGET_H 2 #define WIDGET_H 3 4 #include <QWidget> 5 6 namespace Ui {

Maximum size of QString

梦想的初衷 提交于 2019-12-04 17:35:31
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 have seen the following links but none of them provide a concrete answer: Link 1 Link 2 Since my data

TCPIP 数组传输

别等时光非礼了梦想. 提交于 2019-12-04 06:56:08
最近一直在弄TCPIP进行数据传输,刚刚入门,网上搜了很多例子,今天终于完成了一个小demo 客户端发数组:主要就是数据类型的转化从float 转化成QByteArray //1.建立客户端连接套接字connected 2.建立连接客户端不断监听服务器的信息readyread //3.读取服务器信息readAll 4.设置连接按钮tcpsocket->connectToHost; //5.设置发送信息的按钮write() //6.关闭套接字disconnectFromHost()和close() #include "widget.h" #include "ui_widget.h" #include <QHostAddress> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); tcpsocket = new QTcpSocket(this); connect(tcpsocket,&QTcpSocket::connected, [=]() { QString str = "successfully connect!"; ui->textBrowser->append(str); }); connect(tcpsocket,&QTcpSocket:

QChar to wchar_t

会有一股神秘感。 提交于 2019-12-04 06:32:29
I need to convert a QChar to a wchar_t I've tried the following: #include <cstdlib> #include <QtGui/QApplication> #include <iostream> using namespace std; int main(int argc, char** argv) { QString mystring = "Hello World\n"; wchar_t myArray[mystring.size()]; for (int x=0; x<mystring.size(); x++) { myArray[x] = mystring.at(x).toLatin1(); cout << mystring.at(x).toLatin1(); // checks the char at index x (fine) } cout << "myArray : " << myArray << "\n"; // doesn't give me correct value return 0; } Oh and before someone suggests using the .toWCharArray(wchar_t* array) function, I've tried that and

How to get substring from a string in qt?

一曲冷凌霜 提交于 2019-12-04 05:26:37
I have a text form: Last Name:SomeName, Day:23 ...etc From Last Name:SomeName, I would like to get Last Name, and separately SomeName. I have tried to use QRegularExpression, QRegularExpression re("(?<label>\\w+):(?<text>\\w+)"); But I am getting the result: QString label = match.captured("label") //it gives me only Name What I want is whatever text till ":" to be label, and after to be text. Any ideas? lpapp You could use two different methods for this, based on your need: split() section() main.cpp #include <QString> #include <QDebug> int main() { QString myString = "Last Name:SomeName, Day

数据的封装

让人想犯罪 __ 提交于 2019-12-04 04:39:03
1 怎么创建的数据库? 2 怎么把界面从端口发送到外显屏? 3 打印机的操作? 1 怎么创建的数据库? (1) 把一个QVariantMap 存入数据库: bool Parameter::insertEventData(const QVariantMap &event) { bool bRet = false; if(event.isEmpty()) { return bRet; } QString dbName = QString("./data/YGRecordDB.db"); QString sql = "INSERT INTO eventTable "; QString keys = "( "; //存放字段 QString v = ""; //存放值 QVariantList list; // 存放字段 QVariantMap::const_iterator i = event.constBegin(); while (i != event.constEnd()) { keys += i.key(); keys += ", "; v += "?, "; list << i.value(); // [13,] ++i; } keys = keys.trimmed(); keys = keys.left(keys.length()-1); sql += keys; sql +