qstring

4.自定义信号槽

大兔子大兔子 提交于 2020-01-17 01:42:21
具体实现一个自定义newspaper,reader的信号槽 //!!! Qt5 #include <QObject> ////////// newspaper.h class Newspaper : public QObject { Q_OBJECT public: Newspaper(const QString & name) : m_name(name) { } void send() { emit newPaper(m_name); } signals: void newPaper(const QString &name); private: QString m_name; }; ////////// reader.h #include <QObject> #include <QDebug> class Reader : public QObject { Q_OBJECT public: Reader() {} void receiveNewspaper(const QString & name) { qDebug() << "Receives Newspaper: " << name; } }; ////////// main.cpp #include <QCoreApplication> #include "newspaper.h" #include "reader.h"

Qt 自定义日历控件

左心房为你撑大大i 提交于 2020-01-17 01:13:33
1.ui 界面 2.运行界面 3.源代码 //.h头文件 #ifndef MYCALENDAR_H #define MYCALENDAR_H #include <QWidget> #include <QCalendarWidget> #include <QTextFormat> #include <QPushButton> namespace Ui { class MyCalendar; } //自定义日历类 class MyCalendar : public QWidget { Q_OBJECT public: explicit MyCalendar(QWidget *parent = 0); ~MyCalendar(); private: Ui::MyCalendar *ui; signals: void signal_clickLeftYearButton(); void signal_clickRightYearButton(); void signal_clickLeftMonthButton(); void signal_clickRightMonthButton(); public Q_SLOTS: void slot_leftYearButtonClicked(); void slot_rightYearButtonClicked(); void slot

QT信号和槽函数学习笔记

╄→尐↘猪︶ㄣ 提交于 2020-01-16 23:25:39
//connect 函数有4个参数 分别是 发送者 信号。接受者 ,槽 //connect(sender,signal,receiver,slot) /* * 信号和槽 * 信号 就是一个普通的函数 定义信号的时候需要在函数前面加上signals: ,不需要实现 * 槽 函数 在QT5中科院是类的任意成员函数,静态函数,全局函数 lambda 表达式 * QT4中槽函数的定义 public slots: void send(); * 信号和槽是可以自定义的 * 信号和槽是没有返回值的 * 信号和槽函数可以带参数 * 信号和槽函数的参数必须要一一对应的 * 信号和槽函数的参数可以是不一样的但是槽函数的参数个数可以少于信号的参数个数 * 信号槽函数传参数的数据类型: * 先看QT4的 * connect(sender,SIGNAL(sig1(int,double,Qstring)),receiver,SLOT(slot1(int,double,Qstring))); * SIGNAL 和SLOT 是两个宏 将函数转换成字符串 * 缺点 编译时不会做错误检查 * QT5中 * connect(sender,&sender::sig1,receiver,&receiver::slot1); */ //创建一个按钮对象 QPushButton * Lpbutton =new

Construct QString from QJsonArray in Qt

偶尔善良 提交于 2020-01-16 19:45:09
问题 While trying to construct a QString from values from a QJsonArray , I get the following error: error: passing 'const QString' as 'this' argument discards qualifiers [-fpermissive] . Dunno where I am getting it wrong in this code: QString <CLASS_NAME>::getData(QString callerValue) { QString BASE_URL = "<URL>"; QString stringToReturn = ""; QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { QByteArray barr = reply->readAll(); QJsonParseError jpe;

QString: Remove first occurance of regular expression

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-16 03:58:47
问题 QString has a method remove that takes a QRegExp . It removes every occurrence of the regular expression. Is there a way to remove only the first occurrence of the regular expression? Answer to QString replace only first occurrence doesn't help. See comment from Akiva there. 回答1: You can use next code: QString message = "This is the original text"; QRegExp rx = QRegExp("is|he", Qt::CaseInsensitive); if (message.contains(rx)){ message = message.remove(rx.pos(0), rx.cap(0).size()); } The final

基于qt把ppt转换成pdf

白昼怎懂夜的黑 提交于 2020-01-16 03:12:15
void MainWindow::on_pushButton_2_clicked() { QString fileName = "C:\\Users\\Administrator\\Desktop\\1112.pptx"; QAxObject *_powerPointAxObj = new QAxObject("Powerpoint.Application", 0); if (!_powerPointAxObj) { _powerPointAxObj = new QAxObject("KWPP.Application", 0); if (!_powerPointAxObj) { return; } } _powerPointAxObj->dynamicCall("SetVisible(bool)", false); QAxObject *presentations = _powerPointAxObj->querySubObject("Presentations"); QList<QVariant> paramList; paramList.push_back(QVariant(fileName)); paramList.push_back(0); paramList.push_back(0); paramList.push_back(0); QAxObject

Why do QString and vector<unique_ptr<int>> appear incompatible here?

风格不统一 提交于 2020-01-13 10:33:35
问题 I'm trying to compile some code, which reduces to this: #include <memory> #include <vector> #include <QString> class Category { std::vector<std::unique_ptr<int>> data; QString name; }; int main() { std::vector<Category> categories; categories.emplace_back(); }; Compiled as is, it results in the following error from g++ and similar for clang++: In file included from /opt/gcc-4.8/include/c++/4.8.2/memory:64:0, from test.cpp:1: /opt/gcc-4.8/include/c++/4.8.2/bits/stl_construct.h: In

Why do QString and vector<unique_ptr<int>> appear incompatible here?

有些话、适合烂在心里 提交于 2020-01-13 10:32:29
问题 I'm trying to compile some code, which reduces to this: #include <memory> #include <vector> #include <QString> class Category { std::vector<std::unique_ptr<int>> data; QString name; }; int main() { std::vector<Category> categories; categories.emplace_back(); }; Compiled as is, it results in the following error from g++ and similar for clang++: In file included from /opt/gcc-4.8/include/c++/4.8.2/memory:64:0, from test.cpp:1: /opt/gcc-4.8/include/c++/4.8.2/bits/stl_construct.h: In

QString之arg

非 Y 不嫁゛ 提交于 2020-01-08 00:34:20
QString的arg接口主要用于字符串组合的功能。 arg接口列表 QString arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const QString arg(qlonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const QString arg(qulonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const QString arg(long a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const QString arg(ulong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const QString arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar =

Qt开发中文显示乱码

折月煮酒 提交于 2020-01-07 16:04:39
Qt开发中文显示乱码 来源 https://www.jianshu.com/p/ed269df8104d 参考 https://blog.csdn.net/J_H_C/article/details/93882284 为什么会出现乱码 首先,我们需要有的概念是 乱码的问题是由编码和解码方式引起的 。涉及到编码方式的地方有3个: 源码字符集 执行字符集 运行环境字符集 源码字符集(the source character set):源码文件时使用何种编码格式保存的。 执行字符集(the execution character):可执行程序内保存的是何种编码(程序执行时内存中字符串编码) gcc 运行字符集设置参数 -finput-charset=charset //设置源码字符集为charset -fexec-charset=charset //设置执行字符集为charset -fwide-exec-charset=charset //设置宽字符串的执行字符集为charset msvc 运行字符集设置参数 -execution-charset:utf-8 // 指明程序执行时使用UTF-8字符集 -source-charset:utf-8 // 指明源码文件的编码为UTF-8字符集 源码字符集确切的说是编译器认为源码文件的编码方式,执行字符集是可执行程序采用的编码方式