PyQt转c++Qt记录

优点:qt跨平台,接口简单,易于上手,一定程度上简化了内存回收

成功案例:Linux桌面环境KDE、谷歌地图、VLC多媒体播放器

1.下载安装

链接:https://pan.baidu.com/s/1TbrZ9N_tUafkddXXqxUn3w 
提取码:rfrf

Index of /archive/qt/5.12/5.12.9

网速较慢,可用IDM加速,安装时要登录账号可断网跳过,我试了下QQ的邮箱登不进去。

tools根据需求选,我这里没选MSVC工具链,选的是MinGW,又选了android

最后有launch,点击安装完成后QtCreate会启动。 

Tip:创建桌面快捷方式

 Ctrl+Shift+Esc召唤任务管理器,

打开文件位置,就找到了Qt Creator的路径,之后右键创建快捷方式,再将快捷方式拖到桌面

这里我喜欢暗色主题。qtcreator设置:工具-选项-环境-主题-dark 

二、新建工程 

点击创建项目,选择项目,给项目命名(不能有中文,空格,路径不能有中文)

默认创建窗口的类,积累的选择: QWidget、QMainWindow、QDialog

 HelloWorld

        |--Helloworld.pro    //工程文件

        |--Headers    //头文件

                |--mainwindow.h

        |--Sources

                |--main.cpp    //程序入口

                |--mainwindow.cpp

        |--Forms

                |--mainwindow.ui    // 设计文件,双击进入编辑器(qtdesigner)

Helloworld.pro 

QT       += core gui  #加入core gui模块

#
#    QtWidgets                                    QT Network
#    
#    Qt Webkit                                    QtMulitmedia
#
#    Qt Core                                       Qt Quick Control
#    
#    Qt Gui
#                              Qt5基本模块        Qt Quick Dialog
#    Qt SQL
#
#    Qt Quick
#
#    Qt QML
#
#
#
#
#

#若qt版本高于4, 就加入widgets模块
#因为qt4及以前的QWidgets在QtCore里面
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
#定义的一个宏
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

#指定工程里都有哪些cpp
SOURCES += \
    main.cpp \
    mainwindow.cpp

#指定工程里都有哪些header file
HEADERS += \
    mainwindow.h

#指定工程里都有哪些设计文件
FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp

#include "mainwindow.h"

#include <QApplication> //包含应用程序类的头文件


/*
 * 命令行参数个数,命令行参数数组
 * 应用程序对象有且只有一个
 * argument count (argc)
 * argument vector (argv)
**/
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;   //实例化窗口对象
    w.show();       //显示窗口
    return a.exec();//进入消息循环机制,阻塞
    /*
    c++ 中
    system("pause")放止窗口一闪而过    
    */
}

UI文件的设计类似pyQt,此处不加赘述 

Ctrl+R 或点击左下角三角箭头编译

lineEdit的echoMode设置密码隐藏

右侧帮助-索引可查找相关类的索引

命名规范:

1.类名,首字母大写,单词首字母也大写

2.函数、变量名,首字母小写,单词首字母大写

快捷键:

注释 ctrl + /

编译Ctrl+ b (build)

运行 ctrl + r (run)

字体缩放 ctrl + 鼠标滚轮

查找 Ctrl + f

整行移动 Ctrl + shift + ↑或↓

帮助文档 双击选中要查询的,然后按f1(右键,上下文相关帮助,我电脑f1不好使)

自动对齐 Ctrl + i  (自动缩进)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值