QT6(26)4.3QString:构造(const char *),索引 [ ],QChar 及其测试程序的搭建笔记,ui_widget.h 源码、解析字符对应的 utf-16 编码的按钮的代码实现

(82)

在这里插入图片描述

++ 索引

在这里插入图片描述

(83)QChar

在这里插入图片描述

++其测试效果图:

在这里插入图片描述

++创建选择 widget,以下是其搭建界面的新知识与关键点

在这里插入图片描述

++

在这里插入图片描述

++

在这里插入图片描述

++ 以后学习使用这个控件

在这里插入图片描述

++

在这里插入图片描述
++

在这里插入图片描述

++效果如图

在这里插入图片描述

++给出界面的搭建代码,这有助于理解 QT 与 c++ 的联系,虽然是 QT 编译器帮助咱们自动生成的代码


#ifndef UI_WIDGET_H
#define UI_WIDGET_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Widget
{
public:
    QVBoxLayout *verticalLayout;
    QGroupBox *groupBox;
    QGridLayout *gridLayout;
    QLabel *label;
    QLineEdit *editStr;
    QPushButton *btnUnicode;
    QLabel *label_2;
    QLineEdit *editChar;
    QPushButton *btnCharJudge;
    QGroupBox *groupBox_2;
    QGridLayout *gridLayout_2;
    QPushButton *bntConvLatin1;
    QPushButton *btnConvUTF16;
    QPushButton *btnCompare;
    QPushButton *btnClear;
    QHBoxLayout *horizontalLayout;
    QGroupBox *groupBox_3;
    QGridLayout *gridLayout_3;
    QPlainTextEdit *plainTextEdit;
    QGroupBox *groupBox_4;
    QGridLayout *gridLayout_4;
    QCheckBox *chkIsSymbol;
    QCheckBox *chkIsUpper;
    QCheckBox *chkIsSpace;
    QCheckBox *chkIsMark;
    QCheckBox *chkIsLetter;
    QCheckBox *chkIsDigit;
    QCheckBox *checkBox_4;
    QCheckBox *chkIsPunct;
    QCheckBox *chkIsLower;

    void setupUi(QWidget *Widget)
    {   //const char * QMetaObject::className() const;
        //QString QObject::objectName() const; 返回值不一样
        if (Widget->objectName().isEmpty())
            Widget->setObjectName(QString::fromUtf8("Widget"));
        //void QObject::setObjectName(const QString &name);
        //static QString fromUtf8(const char * utf8, qsizetype size)

        Widget->resize(748, 409);

        //QVBoxLayout::QVBoxLayout(QWidget * parent);
        verticalLayout = new QVBoxLayout(Widget); //此行设置了本窗体的垂直布局

        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));

        groupBox = new QGroupBox(Widget); //容器属于本窗体
        groupBox->setObjectName(QString::fromUtf8("groupBox"));
        gridLayout = new QGridLayout(groupBox); //窗体采用了网格布局
        gridLayout->setObjectName(QString::fromUtf8("gridLayout"));

        label = new QLabel(groupBox);
        label->setObjectName(QString::fromUtf8("label"));
        gridLayout->addWidget(label, 0, 0, 1, 1); //可见,由布局对象来添加子控件

        editStr = new QLineEdit(groupBox);
        editStr->setObjectName(QString::fromUtf8("editStr"));
        gridLayout->addWidget(editStr, 0, 1, 1, 1);

        btnUnicode = new QPushButton(groupBox);
        btnUnicode->setObjectName(QString::fromUtf8("btnUnicode"));
        gridLayout->addWidget(btnUnicode, 0, 2, 1, 1);

        label_2 = new QLabel(groupBox);
        label_2->setObjectName(QString::fromUtf8("label_2"));
        gridLayout->addWidget(label_2, 1, 0, 1, 1);

        editChar = new QLineEdit(groupBox);
        editChar->setObjectName(QString::fromUtf8("editChar"));
        gridLayout->addWidget(editChar, 1, 1, 1, 1);

        btnCharJudge = new QPushButton(groupBox);
        btnCharJudge->setObjectName(QString::fromUtf8("btnCharJudge"));
        gridLayout->addWidget(btnCharJudge, 1, 2, 1, 1);

        verticalLayout->addWidget(groupBox); //把上面的完整容器加入窗体

        groupBox_2 = new QGroupBox(Widget); //开始为窗体准备第二个子容器
        groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
        gridLayout_2 = new QGridLayout(groupBox_2);
        gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));

        bntConvLatin1 = new QPushButton(groupBox_2);
        bntConvLatin1->setObjectName(QString::fromUtf8("bntConvLatin1"));
        gridLayout_2->addWidget(bntConvLatin1, 0, 0, 1, 1);

        btnConvUTF16 = new QPushButton(groupBox_2);
        btnConvUTF16->setObjectName(QString::fromUtf8("btnConvUTF16"));
        gridLayout_2->addWidget(btnConvUTF16, 0, 1, 1, 1);

        btnCompare = new QPushButton(groupBox_2);
        btnCompare->setObjectName(QString::fromUtf8("btnCompare"));
        gridLayout_2->addWidget(btnCompare, 1, 0, 1, 1);

        btnClear = new QPushButton(groupBox_2);
        btnClear->setObjectName(QString::fromUtf8("btnClear"));
        gridLayout_2->addWidget(btnClear, 1, 1, 1, 1);

        verticalLayout->addWidget(groupBox_2); //把第二个完整的容器加入窗体

        horizontalLayout = new QHBoxLayout(); //开始第三个子布局
        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));

        groupBox_3 = new QGroupBox(Widget); //这个子容器只装一个文本框
        groupBox_3->setObjectName(QString::fromUtf8("groupBox_3"));
        gridLayout_3 = new QGridLayout(groupBox_3);
        gridLayout_3->setObjectName(QString::fromUtf8("gridLayout_3"));
        plainTextEdit = new QPlainTextEdit(groupBox_3);
        plainTextEdit->setObjectName(QString::fromUtf8("plainTextEdit"));
        gridLayout_3->addWidget(plainTextEdit, 0, 0, 1, 1); //完成了装文本框的容器

        horizontalLayout->addWidget(groupBox_3); //布局吸入了容器

        groupBox_4 = new QGroupBox(Widget); //装复选框的容器
        groupBox_4->setObjectName(QString::fromUtf8("groupBox_4"));
        gridLayout_4 = new QGridLayout(groupBox_4);
        gridLayout_4->setObjectName(QString::fromUtf8("gridLayout_4"));

        chkIsSymbol = new QCheckBox(groupBox_4); //其行坐标都大了,似乎第一行留给了标题
        chkIsSymbol->setObjectName(QString::fromUtf8("chkIsSymbol"));
        gridLayout_4->addWidget(chkIsSymbol, 3, 0, 1, 1);

        chkIsUpper = new QCheckBox(groupBox_4);
        chkIsUpper->setObjectName(QString::fromUtf8("chkIsUpper"));
        gridLayout_4->addWidget(chkIsUpper, 2, 2, 1, 1);

        chkIsSpace = new QCheckBox(groupBox_4);
        chkIsSpace->setObjectName(QString::fromUtf8("chkIsSpace"));
        gridLayout_4->addWidget(chkIsSpace, 1, 1, 1, 1);

        chkIsMark = new QCheckBox(groupBox_4);
        chkIsMark->setObjectName(QString::fromUtf8("chkIsMark"));
        gridLayout_4->addWidget(chkIsMark, 2, 1, 1, 1);

        chkIsLetter = new QCheckBox(groupBox_4);
        chkIsLetter->setObjectName(QString::fromUtf8("chkIsLetter"));
        gridLayout_4->addWidget(chkIsLetter, 1, 2, 1, 1);

        chkIsDigit = new QCheckBox(groupBox_4);
        chkIsDigit->setObjectName(QString::fromUtf8("chkIsDigit"));
        gridLayout_4->addWidget(chkIsDigit, 1, 0, 1, 1);

        checkBox_4 = new QCheckBox(groupBox_4);
        checkBox_4->setObjectName(QString::fromUtf8("checkBox_4"));
        gridLayout_4->addWidget(checkBox_4, 3, 2, 1, 1);

        chkIsPunct = new QCheckBox(groupBox_4);
        chkIsPunct->setObjectName(QString::fromUtf8("chkIsPunct"));
        gridLayout_4->addWidget(chkIsPunct, 3, 1, 1, 1);

        chkIsLower = new QCheckBox(groupBox_4);
        chkIsLower->setObjectName(QString::fromUtf8("chkIsLower"));
        gridLayout_4->addWidget(chkIsLower, 2, 0, 1, 1);

        horizontalLayout->addWidget(groupBox_4); //水平布局吸入子容器

        verticalLayout->addLayout(horizontalLayout); //垂直总布局吸入子布局

        retranslateUi(Widget); //绘制屏幕上按钮等的名称

        QMetaObject::connectSlotsByName(Widget); //启用信号和槽
    } // setupUi

    void retranslateUi(QWidget *Widget)
    {
        Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
        groupBox->setTitle(QString());
        label->setText(QCoreApplication::translate("Widget", "\350\276\223\345\205\245\345\255\227\347\254\246\344\270\262", nullptr));
        btnUnicode->setText(QCoreApplication::translate("Widget", "\346\257\217\344\270\252\345\255\227\347\254\246\347\232\204Unicode", nullptr));
        label_2->setText(QCoreApplication::translate("Widget", "\350\276\223\345\205\245\345\215\225\344\270\252\345\255\227\347\254\246", nullptr));
        btnCharJudge->setText(QCoreApplication::translate("Widget", "\345\215\225\344\270\252\345\255\227\347\254\246\347\211\271\346\200\247\345\210\244\346\226\255", nullptr));
        groupBox_2->setTitle(QCoreApplication::translate("Widget", "\345\205\266\345\256\203\346\265\213\350\257\225\344\270\216\345\212\237\350\203\275", nullptr));
        bntConvLatin1->setText(QCoreApplication::translate("Widget", "\344\270\216 Latin1 \347\232\204\350\275\254\346\215\242", nullptr));
        btnConvUTF16->setText(QCoreApplication::translate("Widget", "\344\270\216UTF-16\347\232\204\350\275\254\346\215\242", nullptr));
        btnCompare->setText(QCoreApplication::translate("Widget", "QChar\346\257\224\350\276\203\345\222\214\346\233\277\346\215\242", nullptr));
        btnClear->setText(QCoreApplication::translate("Widget", "\346\270\205\347\251\272\346\226\207\346\234\254\346\241\206", nullptr));
        groupBox_3->setTitle(QCoreApplication::translate("Widget", "\346\230\276\347\244\272\347\273\223\346\236\234", nullptr));
        groupBox_4->setTitle(QCoreApplication::translate("Widget", "QChar \347\211\271\346\200\247\345\210\244\346\226\255", nullptr));
        chkIsSymbol->setText(QCoreApplication::translate("Widget", "isSymbol", nullptr));
        chkIsUpper ->setText(QCoreApplication::translate("Widget", "isUpper", nullptr));
        chkIsSpace ->setText(QCoreApplication::translate("Widget", "isSpace", nullptr));
        chkIsMark  ->setText(QCoreApplication::translate("Widget", "isMark", nullptr));
        chkIsLetter->setText(QCoreApplication::translate("Widget", "isLetter", nullptr));
        chkIsDigit ->setText(QCoreApplication::translate("Widget", "isDigit", nullptr));
        checkBox_4 ->setText(QCoreApplication::translate("Widget", "isLetterOrNumber", nullptr));
        chkIsPunct ->setText(QCoreApplication::translate("Widget", "isPunct", nullptr));
        chkIsLower ->setText(QCoreApplication::translate("Widget", "isLower", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Widget: public Ui_Widget {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_WIDGET_H

(84)++ 接下来进行信号与槽的绑定,可以用 connect,也可以用 slotByName

在这里插入图片描述

(85)
谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值