qstring

How can I partition a QByteArray efficiently?

回眸只為那壹抹淺笑 提交于 2019-12-04 03:50:20
问题 I want to partition a QByteArray message efficiently, so this function I implemented take the Bytes, the part I want to extract, and toEnd flag which tells if I want to extract part1 till the end of the array. my dilimeter is spcae ' ' example if I have: ba = "HELLO HOW ARE YOU?" ba1 = getPart(ba, 1, false) -> ba1 = "HELLO" ba2 = getPart(ba, 2, true) -> ba2 = "HOW ARE YOU?" ba3 = getPart(ba, 3, false) -> ba3 = "ARE" the function below works just fine, but I am wondering if this is efficient.

create & post the customized Qevent

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have to create an 2 custom events. I followed this link & made my code :-- Is there a cleaner way to register Qt custom events? Is it the right way to create & post & pass some data(Qstring) to the customized event ? =========================================================== Edit code as per Kuba Ober sugession :--- Mainwindow.h :-- UpdateEvent *myUpdateEvent ; ClearEvent *myClearEvent ; Mainwindow.c :--- MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); i =0; myUpdateEvent = new

QT QString from QDataStream

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working with a buffer and I'm trying to get a string from it, but isnt working... Example: *void myFunc(QDataStream& in) { quint8 v; in >> v; // Ok, I caught v value successfuly QString s; in >> s; // Didnt work :< }* The string lenght is stored on 2 first bytes... Thanks 回答1: If the string was not written as a QString , you need to read its length and content separately. quint8 v; in >> v; quint16 length = 0; in >> length; // the string is probably utf8 or latin QByteArray buffer(length, Qt::Uninitialized); in.readRawData(buffer.data(),

Qt 如何使用反射?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:31:45
Qt 如何使用反射? c++ 反射 标准库暂时还没有,那我们来看看如何使用 qt 来进行反射. 反射类的案例 1. 通过注册的类型需找 id 进行实例化该类 myclass.h #include <QtCore> class MyClass { public: MyClass() {} QString name(){ return "cheungxiongwei"; } }; //声明元对象类型 Q_DECLARE_METATYPE(MyClass) main.cpp #include <QCoreApplication> #include "myclass.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // 注册自定义的类 qRegisterMetaType<MyClass>("MyClass"); // 通过静态函数获取注册类的 id,id 不为 0 时,则获取成功.大部分基础类型都可以获取到 id,如 QString QByteArray int id = QMetaType::type("MyClass"); if(id != 0){ // 根据 id 创建该类型 void *myClass = QMetaType::create(id); // 转换指针 MyClass *my

编译日志—20191101

a 夏天 提交于 2019-12-03 04:53:35
编译日志—20191101 1>------ 已启动全部重新生成: 项目: Project2, 配置: Debug x64 ------ 1> Moc'ing project2.h... 1> Uic'ing project2.ui... 1> Moc'ing teslamanage.h... 1> Rcc'ing project2.qrc... 1>RCC : warning : No resources in 'F:\TeslaManageProject\TeslaManage\Project2\project2.qrc'. 1> 1>cl : 命令行 warning D9002: 忽略未知选项“/SAFESEH:NO” 1> moc_project2.cpp 1> moc_teslamanage.cpp 1> main.cpp 1> project2.cpp 1> teslamanage.cpp 1> 正在生成代码... 1>cl : 命令行 warning D9002: 忽略未知选项“/SAFESEH:NO” 1> qrc_project2.cpp 1>LIBCMTD.lib(initializers.obj) : warning LNK4098: 默认库“msvcrtd.lib”与其他库的使用冲突;请使用 /NODEFAULTLIB:library 1

QT执行shell脚本或者执行linux指令

回眸只為那壹抹淺笑 提交于 2019-12-03 04:24:38
由于我在做linux下的QT开发,有时候会用到shell脚本的辅助,但是需要QT运行shell脚本并获取执行结果,今天给大家分享下我的技巧,废话少说直接上代码: //执行shell指令或者shell脚本的方法 QString Common::executeLinuxCmd(QString strCmd) { QProcess p; p.start("bash", QStringList() <<"-c" << strCmd); p.waitForFinished(); QString strResult = p.readAllStandardOutput(); return strResult; } //实例 QString strResult1 = executeLinuxCmd("sudo sh /home/test.sh"); QString strResult2 = executeLinuxCmd("cat /etc/hostname"); 大家根据自己的业务需求去处理strResult1和strResult2,相信我的代码很清晰了吧!!!    来源: https://www.cnblogs.com/xupeidong/p/11777031.html

Qt error: invalid use of incomplete type &#039;class QLabel&#039;

匿名 (未验证) 提交于 2019-12-03 02:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to compile the following program using QtCreater but I get a lots of errors in this program. I got this program from a book and I'm not able to figure out where the error is. Can someone help debug this program. Here is the FindDialog.h #ifndef FINDDIALOG_H #define FINDDIALOG_H #include <QDialog> class QCheckbox; class QLabel; class QLineEdit; class QPushButton; class FindDialog : public QDialog { Q_OBJECT public: FindDialog(QWidget *parent = 0); signals: void findNext(const QString &str, Qt::CaseSensitivity cs); void findPrevious

phantomjs pdf to stdout

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am desperately trying to output a PDF generated by phantomJS to stdout like here What I am getting is an empty PDF file, although it is not 0 in size, it displays a blank page. var page = require('webpage').create(), system = require('system'), address; address = system.args[1]; page.paperSize = {format: 'A4'}; page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { page.render('/dev/stdout', { format: 'pdf' }); phantom.exit(); }

QByteArray to QString

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having issues with QByteArray and QString . I'm reading a file and stores its information in a QByteArray . The file is in unicode, so it contains something like: t\0 e\0 s\0 t\0 \0 \0 I'm trying to compare this value to my specified value, but it fails, because in the debugger I see it's not an unicode string. The code will explain everything: QByteArray Data; //contains unicode string "t\0 e\0 s\0 t\0 \0 \0" QString myValue = "test"; //value to compare. if(Data.contains(myValue)) //do some stuff. else //do other stuff. In the debugger,

Qt Hide column in QTableView

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to hide the ID column in the table view and i can't do that on my implementation. Can anyone help me? void MainWindow::on_actionClear_Search_triggered() { model = new QStandardItemModel(cars.size(),6,this); //create header createHeader(model); //set data to the table view populate(cars); ui->tableView->setColumnHidden(6,true); ui->tableView->setModel(model); } void MainWindow::createHeader(QStandardItemModel *model){ model->setHorizontalHeaderItem(0,new QStandardItem("Car")); model->setHorizontalHeaderItem(1, new QStandardItem("Type")