当前位置 : 主页 > 网页制作 > HTTP/TCP >

QT_study

来源:互联网 收集:自由互联 发布时间:2021-06-16
https://blog.csdn.net/a313827758/article/details/72736552 https://blog.csdn.net/xbcreal/article/details/52413007#comments 图标制作:https://jingyan.baidu.com/article/636f38bb664fc2d6b84610fa.html 认识 QT main.cpp 基础框架: #inc

https://blog.csdn.net/a313827758/article/details/72736552

 https://blog.csdn.net/xbcreal/article/details/52413007#comments

图标制作:https://jingyan.baidu.com/article/636f38bb664fc2d6b84610fa.html

认识QT

main.cpp基础框架:

#include "mywidget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    //有且只有一个应用程序累的对象
    QApplication a(argc, argv);
    //MyWeight继承QWeight,QWeight是一个窗口基类
    //所以MyWeight也是窗口类
    //w就是一个窗口
    MyWidget w;

    //窗口创建默认是隐藏的,要人为显示
    w.show();

    //a.exec();
    //return 0;
    //让程序一直执行,等待用户操作
    //等待事件的发生
    return a.exec();
}
View Code

 .pro基本框架:

#-------------------------------------------------
#
# Project created by QtCreator 2018-09-17T12:53:54
#
#-------------------------------------------------
#模块
#头文件按f1找
QT       += core gui

#高于qt4版本,添加QT += widgets,为了兼容qt4
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

#应用程序的名字
TARGET = 01Qt_test

#指定makefile的类型,app,lib(库)
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as 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 you use 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

#源文件
SOURCES +=         main.cpp         mywidget.cpp
#头文件
HEADERS +=         mywidget.h
View Code

 QTHelloWorld

main.cpp

#include<QApplication>
#include<QWidget>//窗口控件类型
#include<QPushButton>//按钮

int main(int argc,char **argv)
{
    QApplication app(argc,argv);

    QWidget w;//窗口
    w.setWindowTitle("Hello World!");//设置标题

    /* 如果不指定父对象,对象和对象(窗口和窗口)没有关系,独立
     * a指定b为它的父对象,a放在b上面
     * 指定父对象有两种方法
     * 1、setParent
     * 2、通过构造函数传参
     * 指定父对象,只要父对象显示,上面的子对象自动显示
     */

    QPushButton but;//按钮
    but.setText("^_^");//给按钮设置内容
    but.setParent(&w);//设置父对象
    but.move(100,100);//设置坐标

    QPushButton but1(&w);
    but1.setText("Hello!");

    w.show();
    
    app.exec();
    return 0;
}
View Code

.pro

QT += widgets

SOURCES +=     main.cpp
View Code
网友评论