【Linux】GUI、Qt5

下载Qt5

Qt是一个跨平台的图形框架,在安装了桌面版本的Qt SDK的情况下,用户可以先在PC主机上进行Qt应用程序的开发调试,待应用程序基本成型后,再将
其移植到目标板上。
桌面版本的Qt SDK主要包括以下部分:
用于桌面版本的Qt 库;
集成开发环境 IDE(Qt Creator)。

安装Qt SD

$ sudo apt-get update
$ sudo apt-get install qt5-default # qt-sdk for qt4

在这里插入图片描述

Ubuntu通过安装包进行安装 (1.2G)

官方网址:https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.14/5.14.2/
可以使用chmod增加执行权限。

$ chmod a+x qt-opensource-linux-x64-5.14.2.run
$ ./qt-opensource-linux-x64-5.14.2.run

安装过程中可能需要使用邮箱
请添加图片描述
在这里插入图片描述

查看alarm源代码

alarm代码官方网址:https://doc.qt.io/archives/qt-5.14/qtdoc-tutorials-alarms-example.html
请添加图片描述
可查看代码如main.cpp:

/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QGuiApplication>
#include<QtQuick>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

新建Qt project

命令为:

qtcreator

请添加图片描述
新建请添加图片描述
请添加图片描述
接下来可以一直next完成创建。
项目完成创建之后,点击“运行”,可以得到
请添加图片描述

编译并在Ubuntu上运行

在创建Alarms后在"/"文件下加上所需要的.qml和.cpp文件,
可以直接使用官网上的代码。
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
完成之后“运行”,可以得到:
在这里插入图片描述
注意:在第一次运行时可能遇到如下情况:
请添加图片描述
此时可以通过安装sudo apt-get install qtdeclarative5-dev
来解决问题
请添加图片描述

改变颜色

请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值