Qt5中的QtGui

我在学习Qt查看Qt Creater提供的例子时,遇到了一个小问题。就是明明在代码中包含了QtGui,然而编译的时候还是提示找不到QLabel的定义,以及其他一些类的定义,但是这是官方提供的文档的啊,不应该没通过编译就提供吧,所以就想肯定是自己哪里出了问题,在网上搜了一下果然,归根到底还是版本问题吧,提供的文档估计是版本qt4的,而我自己使用的是qt5,它两个之间的一个区别就是Qt5把关于控件的头文件都移到 <QtWidgets>中了,所以如果在 Qt5 中使用控件应该包含 <QtWidgets>而非<QtGui>。

  1 /****************************************************************************
  2  **
  3  ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
  4  ** Contact: http://www.qt-project.org/legal
  5  **
  6  ** This file is part of the examples of the Qt Toolkit.
  7  **
  8  ** $QT_BEGIN_LICENSE:BSD$
  9  ** You may use this file under the terms of the BSD license as follows:
 10  **
 11  ** "Redistribution and use in source and binary forms, with or without
 12  ** modification, are permitted provided that the following conditions are
 13  ** met:
 14  **   * Redistributions of source code must retain the above copyright
 15  **     notice, this list of conditions and the following disclaimer.
 16  **   * Redistributions in binary form must reproduce the above copyright
 17  **     notice, this list of conditions and the following disclaimer in
 18  **     the documentation and/or other materials provided with the
 19  **     distribution.
 20  **   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 21  **     of its contributors may be used to endorse or promote products derived
 22  **     from this software without specific prior written permission.
 23  **
 24  **
 25  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 26  ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 27  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 28  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 29  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 30  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 31  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 32  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 33  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 34  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 35  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 36  **
 37  ** $QT_END_LICENSE$
 38  **
 39  ****************************************************************************/
 40
 41 #include <QtWidgets>
 42 #include <QTranslator>
 43 #include <QLocale>
 44 #include <QLibraryInfo>
 45
 46
 47  QWizardPage *createIntroPage()
 48  {
 49      QWizardPage *page = new QWizardPage;
 50      page->setTitle("Introduction");
 51
 52      QLabel *label = new QLabel("This wizard will help you register your copy "
 53                                 "of Super Product Two.");
 54      label->setWordWrap(true);
 55
 56      QVBoxLayout *layout = new QVBoxLayout;
 57      layout->addWidget(label);
 58      page->setLayout(layout);
 59
 60      return page;
 61  }
 62
 63  QWizardPage *createRegistrationPage()
 64  {
 65      QWizardPage *page = new QWizardPage;
 66      page->setTitle("Registration");
 67      page->setSubTitle("Please fill both fields.");
 68
 69      QLabel *nameLabel = new QLabel("Name:");
 70      QLineEdit *nameLineEdit = new QLineEdit;
 71
 72      QLabel *emailLabel = new QLabel("Email address:");
 73      QLineEdit *emailLineEdit = new QLineEdit;
 74
 75      QGridLayout *layout = new QGridLayout;
 76      layout->addWidget(nameLabel, 0, 0);
 77      layout->addWidget(nameLineEdit, 0, 1);
 78      layout->addWidget(emailLabel, 1, 0);
 79      layout->addWidget(emailLineEdit, 1, 1);
 80      page->setLayout(layout);
 81
 82      return page;
 83  }
 84
 85  QWizardPage *createConclusionPage()
 86  {
 87      QWizardPage *page = new QWizardPage;
 88      page->setTitle("Conclusion");
 89
 90      QLabel *label = new QLabel("You are now successfully registered. Have a "
 91                                 "nice day!");
 92      label->setWordWrap(true);
 93
 94      QVBoxLayout *layout = new QVBoxLayout;
 95      layout->addWidget(label);
 96      page->setLayout(layout);
 97
 98      return page;
 99  }
100
101  int main(int argc, char *argv[])
102  {
103      QApplication app(argc, argv);
104
105      QString translatorFileName = QLatin1String("qt_");
106      translatorFileName += QLocale::system().name();
107      QTranslator *translator = new QTranslator(&app);
108      if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
109          app.installTranslator(translator);
110
111      QWizard wizard;
112      wizard.addPage(createIntroPage());
113      wizard.addPage(createRegistrationPage());
114      wizard.addPage(createConclusionPage());
115
116      wizard.setWindowTitle("Trivial Wizard");
117  #ifdef Q_OS_SYMBIAN
118      wizard.showMaximized();
119  #else
120      wizard.show();
121  #endif
122
123      return app.exec();
124  }

然后程序就顺利运行了。

Qt5中的QtGui

时间: 2024-08-07 14:28:57

Qt5中的QtGui的相关文章

Qt5 中对 C++11 一些新特性的封装

在 Qt5 中,提供更多 C++11 的特性支持,接下来我们将进行详细的说明. slots (槽) 的 Lambda 表达式 Lambda表达式 是 C++11 中的一个新语法,允许定义匿名函数.匿名函数可用于使用小函数作为参数,而无需显式的进行声明.之前可以通过编写函数指针来达到同样的目的. 在 Qt 4.8 中已经可在一些 QtConcurrent 函数中使用 Lambda 表达式了.但在 Qt5 中甚至可以通过 new connect syntax 来将 Lambda 表达式作为 slot

QT5中运行QT4场景程序 QGraphicsItem *QGraphicsScene::itemAt 函数报错的解决

int main(int argc,char* argv[ ]) { QApplication app(argc,argv); //新建场景 QGraphicsScene scene; //创建矩形图形项 QTransform transform; //QT5添加 transform.rotate(+0.0);//QT5添加 QGraphicsRectItem *item = new QGraphicsRectItem(0, 0, 100, 100); //将图形项添加到场景中 scene.ad

Qt5中的lambda表达式和使用lambda来写connect

c11新特性中加入了lambda表达式,所以Qt 也支持 需在.pro文件中加入 CONFIG += c++11 例子: QString program = "C:/Windows/System32/cmd.exe"; QStringList arguments; arguments << "/c" << "dir" << "C:\\"; QProcess* cmdProcess = new

QT5中如何使用QFtp类(这个类虽然没有被收录,但一直在更新)

由于QT5对QML的支持有很大的改进,所以打算将原来基于QT4的程序移植到QT5上,在移植用QFtp类写的程序时傻眼了! Qt5 移除了 QFtp API,原因是其实现质量.QNetworkAccessManager 可以用来提供 ftp url 的上传下载操作. 由于原来的程序已经跑的很稳定了不想做修改,然后就去想其它办法,结果发现官方说这些 API 将由某一易于迁移的独立形式提供. 鄙人就去git看了看,结果发现这个源码一直在更新,已经更新到支持Qt5了,所以我就下载了一份源码,然后编译了一

QT5 中的乱码问题

1. 一般同意编码方式,就不会产生乱码.统一为utf-8. 2. QT5采用QStringLiteral(""):这种方式来处理字面常量的编码问题,不能处理变量,不能处理数组和容器. 3. QString::fromLocal8Bit("柱身"); 4. 看网上的例子,大都是QT4中的方法,不适用与QT5没有一个成功的. 5. 最好的解决方法是采用国际化,英文翻译.

QT5中如何自定义窗口部件

提升法 eg.(定义一个新的QLable部件)1.定义一个类class Label : public base, public QLabel //可以支持多重继承2.在qt creator中打开ui编辑器,拖曳一个QLable兑现,提升,输入提升的类名Label,勾选全部包含,添加,提升成功. 插件法Qt Assistance:Creating Custom Widgets for Qt Designer1.和提升法一样,也需要先建立一个新的部件类class AnalogClock : publ

Qt5中表格处理大数据量

在Qt中如果是普通项目,GUI处理展现的数据量不大,一般用QTableWidget,QTreeWidget这样的控件就满足了,但是如果数据量行数达到了几万行,那么Widget的展示性能就偏差了. Qt中提供了一种Model/View的编程方式来处理数据,也就是展示层和数据层分离,这样就解耦了.一旦Model的状态改变,它会自动渲染到View控件.这样的机制使得GUI可以展现大量的数据也不会卡顿. 为了处理数据的灵活性,我们用QStandardItemModel来做QTableView的Model

在QT5中实现求两个输入值的和并输出

1.在UI设计界面放置两个输入lineEdit.一个输出TextBrowser和一个PushButton(用以按键求和),如图 2.打开.h文件,在类里面添加槽函数的声明代码,如图  : 3.打开.cpp文件,在文件最下面编写槽函数代码,如图: 由于需要用到QString类型转基本数据类型(int),因此在头文件添加#include <QString> 4.点击运行,在弹出的程序窗口中输入两个数值并点击求和即可,如图

qt5 中登录界面

在设置用户名登录和密码时,可以使用 //设置密码的模式 ui->pwdLineEdit->setEchoMode(QLineEdit::Password); //让字符出现在LineEdit中 ui->pwdLineEdit->setPlaceholderText(tr("请输入用户名")); ui->usrLineEdit->setPlaceholderText(tr("请输入密码")); 如果输入的用户名或者密码不正确, 可以