qt 5.x 学习笔记 (2)

先来放一波过程中用到的资料和官方文档好了。

basic layout_qt5.8

QBoxLayout Class_qt5.8

QString Class 5.8

QChar Class qt 5.8

Standard Dialogs Example qt 5.8

更新的部分还是放在最前面好了。。。

convert from QString to char *的时候有个坑。。。

In order to convert a QString to a char*, then you first need to get a latin1 representation of the string by calling toLatin1() on it which will return a QByteArray. Then call data() on the QByteArray to get a pointer to the data stored in the byte array. See the documentation: See the following example for a demonstration:

举个栗子。。。。

1int main(int argc, char **argv)
2{
3 QApplication app(argc, argv);
4 QString str1 = "Test";
5 QByteArray ba = str1.toLatin1();
6 const char *c_str2 = ba.data(); 
7 printf("str2: %s", c_str2);
8 return app.exec();   
9}
**Note that it is necessary to store the bytearray before you call data() on it, a call like the following const char *c_str2 = str2.toLatin1().data(); will make the application crash as the QByteArray has not been stored and hence no longer exists.**

目前基本框架出来了。。。

可以打开一个文件。。加密。。保存。。。

加密算法部分暂时用倒序输出代替。。。

界面布局还没搞。。。一些提示之类的还没搞。。。。。。。。

接下来要做的。。。大概就是把des写进去了。。。

放一波代码好了。。。

 1/****************************************************************************
 2**
 3** Copyright (C) 2016 The Qt Company Ltd.
 4** Contact: https://www.qt.io/licensing/
 5**
 6** This file is part of the examples of the Qt Toolkit.
 7**
 8** $QT_BEGIN_LICENSE:BSD$
 9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24**   * Redistributions of source code must retain the above copyright
25**     notice, this list of conditions and the following disclaimer.
26**   * Redistributions in binary form must reproduce the above copyright
27**     notice, this list of conditions and the following disclaimer in
28**     the documentation and/or other materials provided with the
29**     distribution.
30**   * Neither the name of The Qt Company Ltd nor the names of its
31**     contributors may be used to endorse or promote products derived
32**     from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
#ifndef DIALOG_H
#define DIALOG_H

#include <QWidget>
#include <QTextEdit>
1class QCheckBox;
2class QLabel;
3class QErrorMessage;
class DialogOptionsWidget;
1class Dialog : public QWidget
2{
3    Q_OBJECT
public:
    Dialog(QWidget *parent = 0);

private slots:

    void setText();
1    void setOpenFileName();
2    void beginToCal();
3    void setSaveFileName();
4    void criticalMessage();
5    void informationMessage();
6    void questionMessage();
7    void warningMessage();
8    void errorMessage();
private:

    QLabel *textLabel;


    QLabel *openFileNameLabel;
 1    QLabel *saveFileNameLabel;
 2    QLabel *criticalLabel;
 3    QLabel *informationLabel;
 4    QLabel *questionLabel;
 5    QLabel *warningLabel;
 6    QLabel *errorLabel;
 7    QErrorMessage *errorMessageDialog;
 8    DialogOptionsWidget *fileDialogOptionsWidget;
 9    DialogOptionsWidget *colorDialogOptionsWidget;
10    DialogOptionsWidget *fontDialogOptionsWidget;
11    QString openFilesPath;
12    QTextEdit *textEdit;
13    QString QTextSt;
14};
#endif
 1/****************************************************************************
 2**
 3** Copyright (C) 2016 The Qt Company Ltd.
 4** Contact: https://www.qt.io/licensing/
 5**
 6** This file is part of the examples of the Qt Toolkit.
 7**
 8** $QT_BEGIN_LICENSE:BSD$
 9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24**   * Redistributions of source code must retain the above copyright
25**     notice, this list of conditions and the following disclaimer.
26**   * Redistributions in binary form must reproduce the above copyright
27**     notice, this list of conditions and the following disclaimer in
28**     the documentation and/or other materials provided with the
29**     distribution.
30**   * Neither the name of The Qt Company Ltd nor the names of its
31**     contributors may be used to endorse or promote products derived
32**     from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
#include <QtWidgets>
#include <QTextEdit>

#include "dialog.h"

#define MESSAGE \
    Dialog::tr("<p>Message boxes have a caption, a text, " \
               "and any number of buttons, each with standard or custom texts." \
               "<p>Click a button to close the message box. Pressing the Esc button " \
               "will activate the detected escape button (if any).")
#define MESSAGE_DETAILS \
    Dialog::tr("If a message box has detailed text, the user can reveal it " \
               "by pressing the Show Details... button.")
1class DialogOptionsWidget : public QGroupBox
2{
3public:
4    explicit DialogOptionsWidget(QWidget *parent = 0);
1    void addCheckBox(const QString &text, int value);
2    void addSpacer();
3    int value() const;
1private:
2    typedef QPair<QCheckBox *, int> CheckBoxEntry;
3    QVBoxLayout *layout;
4    QList<CheckBoxEntry> checkBoxEntries;
5};
1DialogOptionsWidget::DialogOptionsWidget(QWidget *parent) :
2    QGroupBox(parent) , layout(new QVBoxLayout)
3{
4    //setTitle(Dialog::tr("Optionsssss"));
5   // textEdit = new QTextEdit(this);
6    //setCentralWidget(textEdit);
7    //textEdit = new QTextEdit(this);
8    //setCentralWidget(textEdit);
  //  setLayout(layout);
}
1void DialogOptionsWidget::addCheckBox(const QString &text, int value)
2{
3    QCheckBox *checkBox = new QCheckBox(text);
4    layout->addWidget(checkBox);
5    checkBoxEntries.append(CheckBoxEntry(checkBox, value));
6}
1void DialogOptionsWidget::addSpacer()
2{
3    layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
4}
1int DialogOptionsWidget::value() const
2{
3    int result = 0;
4    foreach (const CheckBoxEntry &checkboxEntry, checkBoxEntries)
5        if (checkboxEntry.first->isChecked())
6            result |= checkboxEntry.second;
7    return result;
8}
 1Dialog::Dialog(QWidget *parent)
 2    : QWidget(parent)
 3{
 4    QVBoxLayout *verticalLayout;
 5    if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
 6        QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
 7        QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName(), this);
 8        horizontalLayout->addWidget(groupBox);
 9        verticalLayout = new QVBoxLayout(groupBox);
10    } else {
11        verticalLayout = new QVBoxLayout(this);
12    }
    QToolBox *toolbox = new QToolBox;
    verticalLayout->addWidget(toolbox);

    errorMessageDialog = new QErrorMessage(this);

    int frameStyle = QFrame::Sunken | QFrame::Panel;
1    textLabel = new QLabel;
2    textLabel->setFrameStyle(frameStyle);
3    QPushButton *textButton = new QPushButton(tr("加密文件"));
1    openFileNameLabel = new QLabel;
2    openFileNameLabel->setFrameStyle(frameStyle);
3    QPushButton *openFileNameButton =
4            new QPushButton(tr("打开文件"));
    QPushButton *calButton =
            new QPushButton(tr("加密"));
1    saveFileNameLabel = new QLabel;
2    saveFileNameLabel->setFrameStyle(frameStyle);
3    QPushButton *saveFileNameButton =
4            new QPushButton(tr("QFileDialog::get&SaveFileName()"));
1    criticalLabel = new QLabel;
2    criticalLabel->setFrameStyle(frameStyle);
3    QPushButton *criticalButton =
4            new QPushButton(tr("QMessageBox::critica&l()"));
1    informationLabel = new QLabel;
2    informationLabel->setFrameStyle(frameStyle);
3    QPushButton *informationButton =
4            new QPushButton(tr("QMessageBox::i&nformation()"));
1    questionLabel = new QLabel;
2    questionLabel->setFrameStyle(frameStyle);
3    QPushButton *questionButton =
4            new QPushButton(tr("QMessageBox::&question()"));
1    warningLabel = new QLabel;
2    warningLabel->setFrameStyle(frameStyle);
3    QPushButton *warningButton = new QPushButton(tr("QMessageBox::&warning()"));
1    errorLabel = new QLabel;
2    errorLabel->setFrameStyle(frameStyle);
3    QPushButton *errorButton =
4            new QPushButton(tr("QErrorMessage::showM&essage()"));
    connect(textButton, &QAbstractButton::clicked, this, &Dialog::setText);

    connect(openFileNameButton, &QAbstractButton::clicked,
            this, &Dialog::setOpenFileName);

    connect(calButton,&QAbstractButton::clicked,
            this,&Dialog::beginToCal);
1    connect(saveFileNameButton, &QAbstractButton::clicked,
2            this, &Dialog::setSaveFileName);
3    connect(criticalButton, &QAbstractButton::clicked, this, &Dialog::criticalMessage);
4    connect(informationButton, &QAbstractButton::clicked,
5            this, &Dialog::informationMessage);
6    connect(questionButton, &QAbstractButton::clicked, this, &Dialog::questionMessage);
7    connect(warningButton, &QAbstractButton::clicked, this, &Dialog::warningMessage);
8    connect(errorButton, &QAbstractButton::clicked, this, &Dialog::errorMessage);
1    QWidget *page = new QWidget;
2    QGridLayout *layout = new QGridLayout(page);
3    layout->setColumnStretch(1, 1);
4    layout->setColumnMinimumWidth(1, 250);
    layout->addWidget(textButton, 3, 0);
    layout->addWidget(textLabel, 3, 1);

    layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
    toolbox->addItem(page, tr("Input Dialogs"));

    const QString doNotUseNativeDialog = tr("Do not use native dialog");
1    page = new QWidget;
2    layout = new QGridLayout(page);
3    layout->setColumnStretch(1, 1);
1   /* colorDialogOptionsWidget = new DialogOptionsWidget;
2    colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog);
3    colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel);
4    colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons);
5    layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
6    layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2);
    toolbox->addItem(page, tr("Color Dialog"));
    */
1   // page = new QWidget;
2   // layout = new QGridLayout(page);
3   // layout->setColumnStretch(1, 1);
4   // layout->addWidget(fontButton, 0, 0);
5    //layout->addWidget(fontLabel, 0, 1);
1    page = new QWidget;
2    layout = new QGridLayout(page);
3    layout->setColumnStretch(3,1);
1    layout->addWidget(openFileNameButton, 1, 0);
2    layout->addWidget(openFileNameLabel, 1,1);
3    layout->addWidget(calButton,1,2);
1    layout->addWidget(saveFileNameButton, 3, 0);
2    layout->addWidget(saveFileNameLabel, 3, 1);
3    fileDialogOptionsWidget = new DialogOptionsWidget;
    layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0);
    toolbox->addItem(page, tr("File Dialogs"));
 1    page = new QWidget;
 2    layout = new QGridLayout(page);
 3    layout->setColumnStretch(1, 1);
 4    layout->addWidget(criticalButton, 0, 0);
 5    layout->addWidget(criticalLabel, 0, 1);
 6    layout->addWidget(informationButton, 1, 0);
 7    layout->addWidget(informationLabel, 1, 1);
 8    layout->addWidget(questionButton, 2, 0);
 9    layout->addWidget(questionLabel, 2, 1);
10    layout->addWidget(warningButton, 3, 0);
11    layout->addWidget(warningLabel, 3, 1);
12    layout->addWidget(errorButton, 4, 0);
13    layout->addWidget(errorLabel, 4, 1);
14    layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
    toolbox->addItem(page, tr("Message Boxes"));

    setWindowTitle(QGuiApplication::applicationDisplayName());
}
1void Dialog::setText()
2{
3    bool ok;
4    QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
5                                         tr("User name:"), QLineEdit::Normal,
6                                         QDir::home().dirName(), &ok);
7    if (ok && !text.isEmpty())
8        textLabel->setText(text);
9}
 1void Dialog::setOpenFileName()
 2{
 3    const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
 4    QString selectedFilter;
 5    QString fileName = QFileDialog::getOpenFileName(this,
 6                                tr("QFileDialog::getOpenFileName()"),
 7                                openFileNameLabel->text(),
 8                                tr("All Files (*);;Text Files (*.txt)"),
 9                                &selectedFilter,
10                                options);
11    if (!fileName.isEmpty())
12    {
1        openFileNameLabel->setText(fileName);
2        qDebug()<<"filename:"<<fileName;
3        QFile file(fileName);
        //不仅仅是if判断。。重点是执行了open操作。。。顺便返回值罢了。。kk最菜.jpg
1        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
2            QMessageBox::warning(this, tr("Read File"),
3                                 tr("Cannot open file:\n%1").arg(fileName));
4            return;
5        }
1        QTextStream in(&file);
2        QTextSt = in.readAll();
3        qDebug()<<"fileText:"<<QTextSt<<endl;
4        qDebug()<<"TextLen:"<<QTextSt.length();
5          file.close();
6     }
7}
1void Dialog::beginToCal()
2{
3    int len = QTextSt.length();
4    QString ret = "";
5    for ( int i = len-1 ; i >=0 ; i--)
6    {
7           QChar tmp = QTextSt[i];
8           ret+=tmp;
1    }
2    QTextSt = ret;
3}
 1void Dialog::setSaveFileName()
 2{
 3    const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
 4    QString selectedFilter;
 5    QString fileName = QFileDialog::getSaveFileName(this,
 6                                tr("QFileDialog::getSaveFileName()"),
 7                                saveFileNameLabel->text(),
 8                                tr("All Files (*);;Text Files (*.txt)"),
 9                                &selectedFilter,
10                                options);
 1    if (!fileName.isEmpty())
 2    {
 3        saveFileNameLabel->setText(fileName);
 4        QFile file(fileName);
 5        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
 6            QMessageBox::warning(this, tr("Write File"),
 7                                       tr("Cannot open file:\n%1").arg(fileName));
 8            return;
 9        }
10        QTextStream out(&file);
11        qDebug()<<"save file text:"<<QTextSt<<endl;
12        //out << textEdit->toPlainText();
13        out<<QTextSt<<endl;
14        file.close();
15     }
}
 1void Dialog::criticalMessage()
 2{
 3    QMessageBox::StandardButton reply;
 4    reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
 5                                    MESSAGE,
 6                                    QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
 7    if (reply == QMessageBox::Abort)
 8        criticalLabel->setText(tr("Abort"));
 9    else if (reply == QMessageBox::Retry)
10        criticalLabel->setText(tr("Retry"));
11    else
12        criticalLabel->setText(tr("Ignore"));
13}
1void Dialog::informationMessage()
2{
3    QMessageBox::StandardButton reply;
4    reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
5    if (reply == QMessageBox::Ok)
6        informationLabel->setText(tr("OK"));
7    else
8        informationLabel->setText(tr("Escape"));
9}
 1void Dialog::questionMessage()
 2{
 3    QMessageBox::StandardButton reply;
 4    reply = QMessageBox::question(this, tr("QMessageBox::question()"),
 5                                    MESSAGE,
 6                                    QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
 7    if (reply == QMessageBox::Yes)
 8        questionLabel->setText(tr("Yes"));
 9    else if (reply == QMessageBox::No)
10        questionLabel->setText(tr("No"));
11    else
12        questionLabel->setText(tr("Cancel"));
13}
 1void Dialog::warningMessage()
 2{
 3    QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
 4                       MESSAGE, 0, this);
 5    msgBox.setDetailedText(MESSAGE_DETAILS);
 6    msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
 7    msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
 8    if (msgBox.exec() == QMessageBox::AcceptRole)
 9        warningLabel->setText(tr("Save Again"));
10    else
11        warningLabel->setText(tr("Continue"));
}
 1void Dialog::errorMessage()
 2{
 3    errorMessageDialog->showMessage(
 4            tr("This dialog shows and remembers error messages. "
 5               "If the checkbox is checked (as it is by default), "
 6               "the shown message will be shown again, "
 7               "but if the user unchecks the box the message "
 8               "will not appear again if QErrorMessage::showMessage() "
 9               "is called with the same message."));
10    errorLabel->setText(tr("If the box is unchecked, the message "
11                           "won't appear again."));
12}
 1/****************************************************************************
 2**
 3** Copyright (C) 2016 The Qt Company Ltd.
 4** Contact: https://www.qt.io/licensing/
 5**
 6** This file is part of the examples of the Qt Toolkit.
 7**
 8** $QT_BEGIN_LICENSE:BSD$
 9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24**   * Redistributions of source code must retain the above copyright
25**     notice, this list of conditions and the following disclaimer.
26**   * Redistributions in binary form must reproduce the above copyright
27**     notice, this list of conditions and the following disclaimer in
28**     the documentation and/or other materials provided with the
29**     distribution.
30**   * Neither the name of The Qt Company Ltd nor the names of its
31**     contributors may be used to endorse or promote products derived
32**     from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
1#include <QApplication>
2#include <QStyleHints>
3#include <QDesktopWidget>
4#include <QTranslator>
5#include <QLocale>
6#include <QLibraryInfo>
#include "dialog.h"
1int main(int argc, char *argv[])
2{
3    QApplication app(argc, argv);
4    QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
1#ifndef QT_NO_TRANSLATION
2    QString translatorFileName = QLatin1String("qt_");
3    translatorFileName += QLocale::system().name();
4    QTranslator *translator = new QTranslator(&app);
5    if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
6        app.installTranslator(translator);
7#endif
1    Dialog dialog;
2    if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
3        const QRect availableGeometry = QApplication::desktop()->availableGeometry(&dialog);
4        dialog.resize(availableGeometry.width() * 4 / 5, availableGeometry.height() * 2 / 3);
5        dialog.move((availableGeometry.width() - dialog.width()) / 2,
6                    (availableGeometry.height() - dialog.height()) / 2);
7    }
8    dialog.show();
    return app.exec();
}

记录一些坑?(其实也不算坑。。。

目前我的做法是有一个全局的QString。。。

我是打算直接拆分包装这个QString。。。每8位。。。

然后QString的[] operator得到的是QCharRef类型。。。。

QString之前有的toAscii()被移除了。。。。

qt 5.2以后的方法叫:toLatin1()

qt5.8_doc_toLatin1()