先来放一波过程中用到的资料和官方文档好了。
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****************************************************************************/
50
51#ifndef DIALOG_H
52#define DIALOG_H
53
54#include <QWidget>
55#include <QTextEdit>
56
57class QCheckBox;
58class QLabel;
59class QErrorMessage;
60
61class DialogOptionsWidget;
62
63class Dialog : public QWidget
64{
65 Q_OBJECT
66
67public:
68 Dialog(QWidget *parent = 0);
69
70private slots:
71
72 void setText();
73
74
75 void setOpenFileName();
76 void beginToCal();
77 void setSaveFileName();
78 void criticalMessage();
79 void informationMessage();
80 void questionMessage();
81 void warningMessage();
82 void errorMessage();
83
84private:
85
86 QLabel *textLabel;
87
88
89 QLabel *openFileNameLabel;
90
91 QLabel *saveFileNameLabel;
92 QLabel *criticalLabel;
93 QLabel *informationLabel;
94 QLabel *questionLabel;
95 QLabel *warningLabel;
96 QLabel *errorLabel;
97 QErrorMessage *errorMessageDialog;
98 DialogOptionsWidget *fileDialogOptionsWidget;
99 DialogOptionsWidget *colorDialogOptionsWidget;
100 DialogOptionsWidget *fontDialogOptionsWidget;
101 QString openFilesPath;
102 QTextEdit *textEdit;
103 QString QTextSt;
104};
105
106#endif
107
108
109
110
111
112
113/****************************************************************************
114**
115** Copyright (C) 2016 The Qt Company Ltd.
116** Contact: https://www.qt.io/licensing/
117**
118** This file is part of the examples of the Qt Toolkit.
119**
120** $QT_BEGIN_LICENSE:BSD$
121** Commercial License Usage
122** Licensees holding valid commercial Qt licenses may use this file in
123** accordance with the commercial license agreement provided with the
124** Software or, alternatively, in accordance with the terms contained in
125** a written agreement between you and The Qt Company. For licensing terms
126** and conditions see https://www.qt.io/terms-conditions. For further
127** information use the contact form at https://www.qt.io/contact-us.
128**
129** BSD License Usage
130** Alternatively, you may use this file under the terms of the BSD license
131** as follows:
132**
133** "Redistribution and use in source and binary forms, with or without
134** modification, are permitted provided that the following conditions are
135** met:
136** * Redistributions of source code must retain the above copyright
137** notice, this list of conditions and the following disclaimer.
138** * Redistributions in binary form must reproduce the above copyright
139** notice, this list of conditions and the following disclaimer in
140** the documentation and/or other materials provided with the
141** distribution.
142** * Neither the name of The Qt Company Ltd nor the names of its
143** contributors may be used to endorse or promote products derived
144** from this software without specific prior written permission.
145**
146**
147** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
148** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
149** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
150** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
151** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
152** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
153** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
154** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
155** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
157** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
158**
159** $QT_END_LICENSE$
160**
161****************************************************************************/
162
163#include <QtWidgets>
164#include <QTextEdit>
165
166#include "dialog.h"
167
168#define MESSAGE \
169 Dialog::tr("<p>Message boxes have a caption, a text, " \
170 "and any number of buttons, each with standard or custom texts." \
171 "<p>Click a button to close the message box. Pressing the Esc button " \
172 "will activate the detected escape button (if any).")
173#define MESSAGE_DETAILS \
174 Dialog::tr("If a message box has detailed text, the user can reveal it " \
175 "by pressing the Show Details... button.")
176
177class DialogOptionsWidget : public QGroupBox
178{
179public:
180 explicit DialogOptionsWidget(QWidget *parent = 0);
181
182 void addCheckBox(const QString &text, int value);
183 void addSpacer();
184 int value() const;
185
186private:
187 typedef QPair<QCheckBox *, int> CheckBoxEntry;
188 QVBoxLayout *layout;
189 QList<CheckBoxEntry> checkBoxEntries;
190};
191
192DialogOptionsWidget::DialogOptionsWidget(QWidget *parent) :
193 QGroupBox(parent) , layout(new QVBoxLayout)
194{
195 //setTitle(Dialog::tr("Optionsssss"));
196 // textEdit = new QTextEdit(this);
197 //setCentralWidget(textEdit);
198 //textEdit = new QTextEdit(this);
199 //setCentralWidget(textEdit);
200
201 // setLayout(layout);
202}
203
204void DialogOptionsWidget::addCheckBox(const QString &text, int value)
205{
206 QCheckBox *checkBox = new QCheckBox(text);
207 layout->addWidget(checkBox);
208 checkBoxEntries.append(CheckBoxEntry(checkBox, value));
209}
210
211void DialogOptionsWidget::addSpacer()
212{
213 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
214}
215
216int DialogOptionsWidget::value() const
217{
218 int result = 0;
219 foreach (const CheckBoxEntry &checkboxEntry, checkBoxEntries)
220 if (checkboxEntry.first->isChecked())
221 result |= checkboxEntry.second;
222 return result;
223}
224
225Dialog::Dialog(QWidget *parent)
226 : QWidget(parent)
227{
228 QVBoxLayout *verticalLayout;
229 if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
230 QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
231 QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName(), this);
232 horizontalLayout->addWidget(groupBox);
233 verticalLayout = new QVBoxLayout(groupBox);
234 } else {
235 verticalLayout = new QVBoxLayout(this);
236 }
237
238 QToolBox *toolbox = new QToolBox;
239 verticalLayout->addWidget(toolbox);
240
241 errorMessageDialog = new QErrorMessage(this);
242
243 int frameStyle = QFrame::Sunken | QFrame::Panel;
244
245 textLabel = new QLabel;
246 textLabel->setFrameStyle(frameStyle);
247 QPushButton *textButton = new QPushButton(tr("加密文件"));
248
249 openFileNameLabel = new QLabel;
250 openFileNameLabel->setFrameStyle(frameStyle);
251 QPushButton *openFileNameButton =
252 new QPushButton(tr("打开文件"));
253
254 QPushButton *calButton =
255 new QPushButton(tr("加密"));
256
257
258
259 saveFileNameLabel = new QLabel;
260 saveFileNameLabel->setFrameStyle(frameStyle);
261 QPushButton *saveFileNameButton =
262 new QPushButton(tr("QFileDialog::get&SaveFileName()"));
263
264 criticalLabel = new QLabel;
265 criticalLabel->setFrameStyle(frameStyle);
266 QPushButton *criticalButton =
267 new QPushButton(tr("QMessageBox::critica&l()"));
268
269 informationLabel = new QLabel;
270 informationLabel->setFrameStyle(frameStyle);
271 QPushButton *informationButton =
272 new QPushButton(tr("QMessageBox::i&nformation()"));
273
274 questionLabel = new QLabel;
275 questionLabel->setFrameStyle(frameStyle);
276 QPushButton *questionButton =
277 new QPushButton(tr("QMessageBox::&question()"));
278
279 warningLabel = new QLabel;
280 warningLabel->setFrameStyle(frameStyle);
281 QPushButton *warningButton = new QPushButton(tr("QMessageBox::&warning()"));
282
283 errorLabel = new QLabel;
284 errorLabel->setFrameStyle(frameStyle);
285 QPushButton *errorButton =
286 new QPushButton(tr("QErrorMessage::showM&essage()"));
287
288
289 connect(textButton, &QAbstractButton::clicked, this, &Dialog::setText);
290
291 connect(openFileNameButton, &QAbstractButton::clicked,
292 this, &Dialog::setOpenFileName);
293
294 connect(calButton,&QAbstractButton::clicked,
295 this,&Dialog::beginToCal);
296
297 connect(saveFileNameButton, &QAbstractButton::clicked,
298 this, &Dialog::setSaveFileName);
299 connect(criticalButton, &QAbstractButton::clicked, this, &Dialog::criticalMessage);
300 connect(informationButton, &QAbstractButton::clicked,
301 this, &Dialog::informationMessage);
302 connect(questionButton, &QAbstractButton::clicked, this, &Dialog::questionMessage);
303 connect(warningButton, &QAbstractButton::clicked, this, &Dialog::warningMessage);
304 connect(errorButton, &QAbstractButton::clicked, this, &Dialog::errorMessage);
305
306 QWidget *page = new QWidget;
307 QGridLayout *layout = new QGridLayout(page);
308 layout->setColumnStretch(1, 1);
309 layout->setColumnMinimumWidth(1, 250);
310
311 layout->addWidget(textButton, 3, 0);
312 layout->addWidget(textLabel, 3, 1);
313
314 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
315 toolbox->addItem(page, tr("Input Dialogs"));
316
317 const QString doNotUseNativeDialog = tr("Do not use native dialog");
318
319 page = new QWidget;
320 layout = new QGridLayout(page);
321 layout->setColumnStretch(1, 1);
322
323 /* colorDialogOptionsWidget = new DialogOptionsWidget;
324 colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog);
325 colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel);
326 colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons);
327 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
328 layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2);
329
330 toolbox->addItem(page, tr("Color Dialog"));
331 */
332
333 // page = new QWidget;
334 // layout = new QGridLayout(page);
335 // layout->setColumnStretch(1, 1);
336 // layout->addWidget(fontButton, 0, 0);
337 //layout->addWidget(fontLabel, 0, 1);
338
339
340 page = new QWidget;
341 layout = new QGridLayout(page);
342 layout->setColumnStretch(3,1);
343
344 layout->addWidget(openFileNameButton, 1, 0);
345 layout->addWidget(openFileNameLabel, 1,1);
346 layout->addWidget(calButton,1,2);
347
348 layout->addWidget(saveFileNameButton, 3, 0);
349 layout->addWidget(saveFileNameLabel, 3, 1);
350 fileDialogOptionsWidget = new DialogOptionsWidget;
351
352
353 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0);
354 toolbox->addItem(page, tr("File Dialogs"));
355
356
357 page = new QWidget;
358 layout = new QGridLayout(page);
359 layout->setColumnStretch(1, 1);
360 layout->addWidget(criticalButton, 0, 0);
361 layout->addWidget(criticalLabel, 0, 1);
362 layout->addWidget(informationButton, 1, 0);
363 layout->addWidget(informationLabel, 1, 1);
364 layout->addWidget(questionButton, 2, 0);
365 layout->addWidget(questionLabel, 2, 1);
366 layout->addWidget(warningButton, 3, 0);
367 layout->addWidget(warningLabel, 3, 1);
368 layout->addWidget(errorButton, 4, 0);
369 layout->addWidget(errorLabel, 4, 1);
370 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
371
372 toolbox->addItem(page, tr("Message Boxes"));
373
374 setWindowTitle(QGuiApplication::applicationDisplayName());
375}
376
377
378
379
380
381void Dialog::setText()
382{
383 bool ok;
384 QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
385 tr("User name:"), QLineEdit::Normal,
386 QDir::home().dirName(), &ok);
387 if (ok && !text.isEmpty())
388 textLabel->setText(text);
389}
390
391
392
393
394
395
396
397
398void Dialog::setOpenFileName()
399{
400 const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
401 QString selectedFilter;
402 QString fileName = QFileDialog::getOpenFileName(this,
403 tr("QFileDialog::getOpenFileName()"),
404 openFileNameLabel->text(),
405 tr("All Files (*);;Text Files (*.txt)"),
406 &selectedFilter,
407 options);
408 if (!fileName.isEmpty())
409 {
410
411 openFileNameLabel->setText(fileName);
412 qDebug()<<"filename:"<<fileName;
413 QFile file(fileName);
414
415 //不仅仅是if判断。。重点是执行了open操作。。。顺便返回值罢了。。kk最菜.jpg
416
417 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
418 QMessageBox::warning(this, tr("Read File"),
419 tr("Cannot open file:\n%1").arg(fileName));
420 return;
421 }
422
423 QTextStream in(&file);
424 QTextSt = in.readAll();
425 qDebug()<<"fileText:"<<QTextSt<<endl;
426 qDebug()<<"TextLen:"<<QTextSt.length();
427 file.close();
428 }
429}
430
431
432
433void Dialog::beginToCal()
434{
435 int len = QTextSt.length();
436 QString ret = "";
437 for ( int i = len-1 ; i >=0 ; i--)
438 {
439 QChar tmp = QTextSt[i];
440 ret+=tmp;
441
442 }
443 QTextSt = ret;
444}
445
446void Dialog::setSaveFileName()
447{
448 const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
449 QString selectedFilter;
450 QString fileName = QFileDialog::getSaveFileName(this,
451 tr("QFileDialog::getSaveFileName()"),
452 saveFileNameLabel->text(),
453 tr("All Files (*);;Text Files (*.txt)"),
454 &selectedFilter,
455 options);
456
457 if (!fileName.isEmpty())
458 {
459 saveFileNameLabel->setText(fileName);
460 QFile file(fileName);
461 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
462 QMessageBox::warning(this, tr("Write File"),
463 tr("Cannot open file:\n%1").arg(fileName));
464 return;
465 }
466 QTextStream out(&file);
467 qDebug()<<"save file text:"<<QTextSt<<endl;
468 //out << textEdit->toPlainText();
469 out<<QTextSt<<endl;
470 file.close();
471 }
472
473
474}
475
476void Dialog::criticalMessage()
477{
478 QMessageBox::StandardButton reply;
479 reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
480 MESSAGE,
481 QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
482 if (reply == QMessageBox::Abort)
483 criticalLabel->setText(tr("Abort"));
484 else if (reply == QMessageBox::Retry)
485 criticalLabel->setText(tr("Retry"));
486 else
487 criticalLabel->setText(tr("Ignore"));
488}
489
490void Dialog::informationMessage()
491{
492 QMessageBox::StandardButton reply;
493 reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
494 if (reply == QMessageBox::Ok)
495 informationLabel->setText(tr("OK"));
496 else
497 informationLabel->setText(tr("Escape"));
498}
499
500void Dialog::questionMessage()
501{
502 QMessageBox::StandardButton reply;
503 reply = QMessageBox::question(this, tr("QMessageBox::question()"),
504 MESSAGE,
505 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
506 if (reply == QMessageBox::Yes)
507 questionLabel->setText(tr("Yes"));
508 else if (reply == QMessageBox::No)
509 questionLabel->setText(tr("No"));
510 else
511 questionLabel->setText(tr("Cancel"));
512}
513
514void Dialog::warningMessage()
515{
516 QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
517 MESSAGE, 0, this);
518 msgBox.setDetailedText(MESSAGE_DETAILS);
519 msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
520 msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
521 if (msgBox.exec() == QMessageBox::AcceptRole)
522 warningLabel->setText(tr("Save Again"));
523 else
524 warningLabel->setText(tr("Continue"));
525
526}
527
528void Dialog::errorMessage()
529{
530 errorMessageDialog->showMessage(
531 tr("This dialog shows and remembers error messages. "
532 "If the checkbox is checked (as it is by default), "
533 "the shown message will be shown again, "
534 "but if the user unchecks the box the message "
535 "will not appear again if QErrorMessage::showMessage() "
536 "is called with the same message."));
537 errorLabel->setText(tr("If the box is unchecked, the message "
538 "won't appear again."));
539}
540
541
542
543
544
545
546/****************************************************************************
547**
548** Copyright (C) 2016 The Qt Company Ltd.
549** Contact: https://www.qt.io/licensing/
550**
551** This file is part of the examples of the Qt Toolkit.
552**
553** $QT_BEGIN_LICENSE:BSD$
554** Commercial License Usage
555** Licensees holding valid commercial Qt licenses may use this file in
556** accordance with the commercial license agreement provided with the
557** Software or, alternatively, in accordance with the terms contained in
558** a written agreement between you and The Qt Company. For licensing terms
559** and conditions see https://www.qt.io/terms-conditions. For further
560** information use the contact form at https://www.qt.io/contact-us.
561**
562** BSD License Usage
563** Alternatively, you may use this file under the terms of the BSD license
564** as follows:
565**
566** "Redistribution and use in source and binary forms, with or without
567** modification, are permitted provided that the following conditions are
568** met:
569** * Redistributions of source code must retain the above copyright
570** notice, this list of conditions and the following disclaimer.
571** * Redistributions in binary form must reproduce the above copyright
572** notice, this list of conditions and the following disclaimer in
573** the documentation and/or other materials provided with the
574** distribution.
575** * Neither the name of The Qt Company Ltd nor the names of its
576** contributors may be used to endorse or promote products derived
577** from this software without specific prior written permission.
578**
579**
580** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
581** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
582** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
583** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
584** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
585** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
586** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
587** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
588** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
589** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
590** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
591**
592** $QT_END_LICENSE$
593**
594****************************************************************************/
595
596#include <QApplication>
597#include <QStyleHints>
598#include <QDesktopWidget>
599#include <QTranslator>
600#include <QLocale>
601#include <QLibraryInfo>
602
603#include "dialog.h"
604
605int main(int argc, char *argv[])
606{
607 QApplication app(argc, argv);
608 QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
609
610#ifndef QT_NO_TRANSLATION
611 QString translatorFileName = QLatin1String("qt_");
612 translatorFileName += QLocale::system().name();
613 QTranslator *translator = new QTranslator(&app);
614 if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
615 app.installTranslator(translator);
616#endif
617
618 Dialog dialog;
619 if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
620 const QRect availableGeometry = QApplication::desktop()->availableGeometry(&dialog);
621 dialog.resize(availableGeometry.width() * 4 / 5, availableGeometry.height() * 2 / 3);
622 dialog.move((availableGeometry.width() - dialog.width()) / 2,
623 (availableGeometry.height() - dialog.height()) / 2);
624 }
625 dialog.show();
626
627 return app.exec();
628}记录一些坑?(其实也不算坑。。。
目前我的做法是有一个全局的QString。。。
我是打算直接拆分包装这个QString。。。每8位。。。
然后QString的[] operator得到的是QCharRef类型。。。。
QString之前有的toAscii()被移除了。。。。
qt 5.2以后的方法叫:toLatin1()