LIke's blog

Write down my thoughts

近期

2024年10月11日
学校里挺忙的

  • 统计学STA2001
    • 整理一篇分布作为post发出来
    • 还有一篇关于mgf的post
  • 最优化MAT3007
    • 整理一篇Simplex method作为post发出来(预计用时6h)
  • CSC3002 C++
    • 学习SDL2,Post记录问题
    • 为了方便项目开展,抽空写一篇和GitHub功能相关的博客,比如project,issue等功能
  • CSC3100 算法
    • 整理一篇时间复杂度计算作为post发出来
    • 学习A2

本博客推荐

本博客分类介绍

  • RM 记录robomaster相关知识(其实就是杂项)
  • daily 记录日常
  • web 记录网络相关
    • blog 记录与博客相关
  • C/C++ 记录C/C++语法相关

Qt版本:Qt 6.7.2 项目配置

本教程参考哔哩哔哩系列视频
help -> about qt creater查看版本

在Qt中创建一个GUI项目

step 1: choose a template

选择一个模板,这里选择一个空的模板
Qt widgets application

  • 可以看到有图标,根据图标大概能知道这个模板是什么模板
  • 右边也会有对模板的描述

step 2: Project location

选择你的文件位置,命名的你文件名字

step 3: Define Build System

  • 选择CMake,可以参考这里
  • 什么是[[CSC3002/01_CSC3002_note/Build system|Build system]]
  • 我跟教程走,选择qmake
  • 项目管理文件qmake -> .pro文件; cmake -> CMakeLists.txt文件

step 4: class information

widget: used to refer to any small device that you do not know the name of(不知名的)小器物,小装置,小玩意儿( informal ) from oxford

  • widget空窗口(只有窗口标题)
    • mianWindow主窗口(菜单栏等)
    • dialog对话框(有Yes or no的选项)
  • 建议类名选择大写开头
  • 勾选后有widget.ui的文件,这个文件会有ui的信息
    选择翻译后的语言,存储在zh_CN.qm文件中,我们用英文开发,有中文的语言包

step 5: Kit selection

编译套件的选择,选择Qt自带的编译器 MinGW 64-bit

step 6: 版本控制系统选择

代码同步工具

  • SVN
  • GIT

finish

完成!
如果高版本的Qt可能出现报错和警告,尝试:help -- about plugins -- c++ -- ClangCodeModle取消勾选,重启软件。

效果展示:Hello world in Window

in widget.ui design中的窗口设计, 选择一个label和一个push button(the advantage of qt is that you can drag and drop to design the window))

trouble shooting

点击.pro多数能打开项目,因为qmake是默认的构建系统

点击CMakeLists.txt无法正常打开项目

确认cmake是否安装

  1. type cmake --version in cmd, 你会得到cmake的版本号
  2. else安装cmake from here

确认环境变量是否配置正确

  1. type echo %PATH% in cmd, 你会得到目前你所有的 PATH,检查qt是否在里面
  2. 注意:区分QtCreator 和 Qt,QtCreator是IDE,Qt是库
  3. 注意:Path在用户变量有时不会正常生效(Kimi的观点)设置在系统变量

issue查看configuration fail的原因

每个人的原因可能不一样

我的是build type的问题,我选择了debug,但是我的debug没有配置

  1. 清理构建目录clear CMake configuration:清理您的构建目录,以确保与构建缓存和配置无关的干净状态。您可以在 Qt Creator 中通过“构建”菜单中的“清理项目”选项清理构建目录。
  2. 重新配置项目run CMake:重新配置项目

尝试Qt自带的案例examples,感受项目的效果


p.s.

  • in left sidebar projectsyou see the calqlatre is in bold font, that means it is the current active project
  • you can see the compiling process in the compile output in the bottom
  • you can see the issues in the bottom, if there is any error, you can see it here
  • the calculator window will pop up after compiling
  • 先build (锤子)后 run (绿三角)

AI生成的回答(仅参考)

build debug /release 区别

Debug 构建:

  1. 编译优化:通常不进行优化或仅进行最小优化,以便于调试。
  2. 调试信息:包含完整的调试信息,如符号信息,这有助于调试器定位代码中的问题。
  3. 执行速度:由于没有优化,执行速度通常较慢。
  4. 错误检查:包含额外的错误检查和断言,有助于在开发过程中发现问题。
  5. 内存使用:可能会使用更多的内存,因为优化较少。
  6. 日志记录:可能会包含更详细的日志记录,以帮助追踪问题。
  7. 符号名称:变量和函数名称不会被优化掉,保持源代码中的名称,便于调试。

Release 构建:

  1. 编译优化:进行高度优化,以提高应用程序的性能。
  2. 调试信息:通常不包含调试信息,或只包含非常有限的调试信息。
  3. 执行速度:由于进行了优化,执行速度较快。
  4. 错误检查:错误检查和断言可能会被禁用或减少,以避免影响性能。
  5. 内存使用:优化内存使用,以减少应用程序的内存占用。
  6. 日志记录:日志记录可能会被禁用或减少,以避免影响性能。
  7. 符号名称:变量和函数名称可能会被缩短,以减少二进制文件的大小。

为什么需要不同的构建方式?

  • 开发和调试:Debug 构建提供了必要的调试信息和工具,帮助开发者在开发过程中发现和修复错误。
  • 性能测试:Release 构建通过优化提供了应用程序的最佳性能,这对于性能测试和最终用户是非常重要的。
  • 部署:最终用户通常使用 Release 构建,因为它提供了更好的性能和更小的二进制文件大小。

在实际开发过程中,开发者可能会在 Debug 模式下编写和测试代码,然后切换到 Release 模式进行性能测试和部署。

build和compile的区别

编译(Compile):

  1. 定义:编译是将源代码(通常是单个文件,如 .c.cpp 文件等)转换成机器码的过程,生成的目标文件通常具有 .obj 或 .o 扩展名。
  2. 编译器:编译过程通常由编译器完成,如 GCC、Clang、MSVC 等。
  3. 单个文件:编译通常针对单个源文件,将其从高级语言转换为低级语言。
  4. 语法检查:编译过程中,编译器会检查语法错误。
  5. 优化:编译器可能会对代码进行优化,以提高性能或减少生成的机器代码的大小。

构建(Build):

  1. 定义:构建是一个更广泛的过程,它包括编译、链接等多个步骤,将多个源文件和资源(如库文件、资源文件等)组合成一个可执行文件或库文件。
  2. 构建系统:构建过程通常由构建系统或构建工具管理,如 Make、CMake、MSBuild、Ant 等。
  3. 多个文件:构建过程涉及多个源文件和可能的库文件。
  4. 依赖管理:构建系统会管理文件之间的依赖关系,并确定编译的顺序。
  5. 链接:构建过程包括链接步骤,将编译后的目标文件与库文件链接在一起,生成最终的可执行文件或库文件。
  6. 自动化:构建过程可以自动化,通常通过编写构建脚本来定义构建的规则和步骤。

区别:

  • 范围:编译是构建过程中的一个步骤,构建是一个更全面的过程。
  • 目标:编译的目标是生成目标文件,而构建的目标是生成可执行文件或库文件。
  • 过程:编译过程关注单个源文件的转换,构建过程关注整个项目从源代码到可执行文件的完整流程。

git 教程

push操作流程

确保这是一个仓库.git文件存在

  • git status 查看当前状态,记得查看branch
  • git add * 添加所有要更改的文件到暂存区(stage)
  • git commit -m "<message>" 提交暂存区到仓库区(commit)
  • git push origin main把本地库的内容推送到远程
    你可以参考 cs61b lab1 section E 十分好的 git 教程

fetch/pull操作流程

如果你只是为了更新本地文件,可以使用 git pull 命令从远程仓库获取最新的更改并合并到你的本地分支。以下是步骤:
git checkout main
(checkout)切换到你想要更新的分支(通常是 main 或 master 分支):
git pull origin main
拉取远程仓库的最新更改并合并到本地分支:

  • git fetch origin main 从远程获取最新版本到本地,不会自动merge
  • git pull origin main 把远程库(origin和远程库的URL等价)的内容拉下来,然后与本地的文件合并

merge(合并)

  1. 本地分支合并:你可以在本地将一个分支合并到另一个分支。
    feature-branch 是你要合并的分支,main 是目标分支。一般在freture branch开发新功能或修复bug.
    1
    2
    git checkout main
    git merge feature-branch
  2. 解决冲突:如果在合并过程中发生冲突,你需要在本地解决这些冲突,然后提交解决后的文件。
    1
    2
    3
    give your resolved file to git
    git add <resolved-files>
    git commit -m "Resolved merge conflicts"
  3. 推送到远程:合并完成并解决冲突后,你可以将合并后的分支推送到远程仓库。
    git push origin main

分支branch

并行开发必备

  • git branch 查看分支,确认当前的分支信息
    step 1: git branch <branch-name> 创建分支
    step 2: 在新分支上开发功能
    1
    2
    git add *
    git commit -m "My new feature"
    step 3: 推送新分支到远程仓库git push origin <feature-branch>
    step 4: 切换到主分支git checkout main
    step 5: 合并分支git merge <feature-branch>
    step 6: 删除分支git branch -d <feature-branch>
    step 7: 删除远程分支git push origin --delete <feature-branch>
Read more »

教程

检查版本

Qt use MINGW, so download SDL2 in correspond version

主要参考的教程
次要参考的教程
比较全面的教程是,不过介绍用的是VS,导出模板,CMake配置也教了
环境路径设置好,对库的链接在pro文件中配置好,主程序中include即可。

个人疑问和AI回答

以下图片是下载下来的目录。
里面有lib ,mingw相关的有i686...x86_64-w64他们之间有什么不同吗?

动态库和静态库的使用场景

lib文件夹通常包含编译好的库文件,这些库文件是用于链接到你的应用程序中的,而不是直接用于运行时的。在Windows系统中,库文件通常是静态库(.lib)或动态库(.dll)dynamic link library,其中:

  • .lib文件是静态库文件,它们在编译时被链接到你的应用程序中,使得库的代码成为应用程序的一部分。
  • .dll文件是动态链接库文件,它们在运行时被应用程序加载,允许多个程序共享同一份库代码。

对于SDL(Simple DirectMedia Layer)这样的库,如果你需要在运行时动态加载库(比如在不支持静态链接的环境中),你应该使用.dll文件。在x86_64-w64-mingw32这样的目录下,通常会提供编译好的.dll文件,用于64位的Windows系统。

直接选择lib文件夹可能不会给你正确的文件类型或架构版本的库文件。你需要根据你的应用程序的需要(静态或动态链接)以及目标平台(32位或64位)来选择正确的文件。对于64位系统,确保选择的是64位的.dll文件,这样可以保证最佳的性能和兼容性。

两个mingw前缀的区别

i686是一个指令集架构,它是Intel 80686微处理器的简称,属于x86架构的32位版本。在Linux系统中,i686通常用来表示32位的Intel或AMD处理器。这个架构的名称来源于最初的80686处理器,尽管现代的处理器已经远远超出了最初的686型号的性能。

在编译软件或库时,如果你的目标是为32位的x86系统编译:

  • 在Linux发行版中,32位的库文件通常位于以i686命名的文件夹中。
  • 在Windows系统中,32位的库文件通常位于以x86命名的文件夹中。

对于64位系统,你应该选择64位的库文件(例如x86_64-w64-mingw32中的文件)

在发行版中tar和gz是什么

mingw.tar.gz 文件名中的 targz 分别代表两种不同的压缩和归档技术:

  1. tar:这是一个用于将多个文件和目录打包成一个单独文件的工具,通常用于在 Unix 和类 Unix 系统中。tar 本身并不压缩文件,它只将文件和目录归档。
  2. gz:这是 Gzip(GNU Zip)的文件扩展名,表示该文件经过压缩以减少其大小。Gzip 是一种常见的压缩算法,通常用于压缩 tar 归档文件。

结语

跟着教程配置环境不难,但是相关的信息对我这种新手而言还是有许多不懂的。

Intro

于我个人而言GitHub是上大学才开始用的,在广东省的义务教育阶段,计算机相关的教育是欠缺的。我身边有同校高排名同学大一一整年没接触GitHub,也有内地名牌985同学依然使用微信传输文件进行项目开发。

整个大一GitHub我只会clone,push,pull的基础操作。但是GitHub的功能很多,诸如issue, project, release 都很让我好奇,也相应的有各自不可或缺的功能。所以趁着CSC3002 C++ 项目的机会,我决定系统的学习一下GitHub的功能。

在抄教程部署我的静态博客时意识到参考官方文档的重要性,本次教程主要材料是 GitHub官方教程。文内未标注出处默认来自官网。
在这个教程中,我会把我认为重要的部分记录下来,以便日后查阅。你有不懂的应该上官网查阅

Note that: all the posts with “note” in their title are notes based on some materials (tutorial, lecture, etc.) I once working on.

基础

repo创建

repo是什么

  • repo就是一个云端的文件夹,可以用来存放代码,文档,图片等等。是repository(仓库)的缩写。
  • see more repo

repo的作用

  • 最基本:管理项目的文件
  • 你可以用GitHub Pages的服务创建个人网站
  • 你可以用创建和你用户名一样的repo来展示你的profile README,这回显示在你的个人主页上
  • GitHub右上角Watch、Star和Fork详解

repo的类型

  • repo 分为public和private两种,public是公开的,private是私有的。private会消耗action minutes
    • Action minute 是GitHub Actions服务 的计算单位(就像话费用时间计算),是用来运行自动化任务的。
  • ![[image/GitHub_note.png]]
  • 上方图片是自动填写好的字段直接创建默认reposkills-introduction-to-github,我就不放图床了,你自己实践。
  • README.md 在20s会刷新一次,直接进入到教程的第二阶段 - branch,这个是GitHub Action实现的

branch创建

  • Fork 是在远程创建一个仓库副本,适合独立开发和对外部项目的贡献。
  • Branch 是在同一个仓库内创建的开发线,适合组织和管理团队内部的开发工作。

什么是branch

  • 把main看作是项目的主线,branch是在主线上的一个分支,可以用来开发新功能,修复bug等等。创建branch的目的是为了不影响main的稳定性。
  • see more branch
  • The main branch drop-down bar(下拉栏) will reflect your new branch and display the new branch name.
  • ![[image/GitHub_note-1.png]]
  • 确保名字是my-first-branch,会触发GitHub Action去推进教程
  • ![[image/GitHub_note-2.png]]

commit - 在branch里面

commit是什么

What is a commit?: A commit is a set of changes to the files and folders in your project. A commit exists in a branch. For more information, see “About commits“.

  • commit一个PROFILE.md文件
  • commit一个PROFILE.md文件的更新
    以上都是commit的操作

pull request - 创建并完成

What is a pull request?: Collaboration happens on a pull request. The pull request shows the changes in your branch to other people and allows people to accept, reject, or suggest additional changes to your branch. In a side by side comparison, this pull request is going to keep the changes you just made on your branch and propose applying them to the main project branch. For more information about pull requests, see “About pull requests“.

pull request是为了让别人看到你在branch上的变动,然后别人可以接受,拒绝或者建议更改你的branch。这个pull request是为了把你在branch上的变动应用到main项目分支上。

  • 独立开发:通常的工作流程是先fork一个仓库,然后clone你自己的fork到本地进行开发。开发完成后,你可以提交pull request到原仓库,请求合并你的代码。
  • 团队开发:在一个团队中,通常会有一个主仓库,团队成员会在主仓库的main分支上创建自己的分支进行开发。开发完成后,他们会提交pull requestmain分支,请求合并他们的代码。

主窗口元素

时间线

[[image/GitHub_note-3.png]]

[[image/GitHub_note-6.png]]

所有的变动都会被记录在主窗口中,你可以看到每次commit的变动(时间,作者),然后对于pull request的变动也会在时间线里面体现。

为什么管理者可以修改评论!?

在一些版本控制平台上,特别是GitHub,用户可以编辑或修改他人的评论通常是出于以下几种原因:

  1. 权限设置:项目的权限可能设置为允许特定角色(例如维护者或项目管理员)编辑任何人的评论。这有助于团队维护清晰和一致的讨论。
  2. 修正错误:有时评论可能包含拼写错误或错误的信息,允许编辑可以确保讨论的准确性。
  3. 更新信息:在持续的讨论中,信息可能会过时或需要补充,编辑评论可以让讨论更加连贯。
  4. 审查和维护:在大型项目中,维护者可能需要编辑评论以整理讨论,确保重要信息突出显示。
    如果你在一个项目中发现可以修改他人的评论,确保在这样做之前获得相关人员的同意,以维护良好的合作氛围和信任。

完成merge后删除branch

[[image/GitHub_note-8.png]]

边栏元素

reviewer(审查人)和 assignees(指定人)

审查就是设置reviewer在merge前审查,减少错误。assignees被指定完成接下来的任务
CSDN疑似AI的详细解答

labels(标签)

标签的作用是标记issue和pull request的状态,比如这次pull requst的目的是什么。
打开下拉菜单Apply lables to this pull request 你会看到

  • bug
  • documentation
  • duplicate
  • enhancement
  • good first issue:鼓励新手参与
  • help wanted
  • invalid
  • question
  • wontfix:描述的问题是一个bug但是将永远不会被修复
  • 管理标签 - GitHub 文档

projects(项目)和 milestone(里程碑)

  • 把pull request加入到项目中,可以更好的管理项目
  • 把pull request加入到里程碑中,可以更好的管理项目,你可以理解为这次pull request是项目的一个阶段的结束。

lock conversation(锁定对话)

![[image/GitHub_note-7.png]]

重要信息能被看到

完成教程

(https://github.com/humble-learner006/skills-introduction-to-github?tab=readme-ov-file#finish)这是GitHub里面标题锚点设置方法

Finish存档

Congratulations, you’ve completed this course and joined the world of developers!
Here’s a recap of your accomplishments:

  • You learned about GitHub, repositories, branches, commits, and pull requests.
  • You created a branch, a commit, and a pull request.
  • You merged a pull request.
  • You made your first contribution! 🎉
    所以说contribution是被接受的pull request。那那个改了一个空行能被接受的小红书用户真是牛逼。

What’s next? 给出了接下来可以学什么

profile README是一个在你个人主页的readme

If you’d like to make a profile README, use the quickstart instructions below or follow the instructions in the Managing your profile README article.

  1. Make a new public repository with a name that matches your GitHub username.
  2. Create a file named README.md in its root. The “root” means not inside any folder in your repository.
  3. Edit the contents of the README.md file.
  4. If you created a new branch for your file, open and merge a pull request on your branch.
  5. Lastly, we’d love to hear what you thought of this course in our discussion board.
Check out these resources to learn more or get involved:

进阶

GitHub Issue:提出议题,想法

关于议题 - GitHub 文档

GitHub Project:管理进度

关于 Projects - GitHub 文档
此处的project是指GitHub的项目管理功能,可以用来管理任务,协作等等。与其说是project,不如说是dashboard或者kanban更合适。
[[image/GitHub_note-12.png]]

Kanban originate from Japanese 看板 # Japanese influences on industry

  • 是一个和issue,pull request,milestone等等一起工作的工具,可以用来管理任务,协作等等。
  • 高级todo list

GitHub release:发行程序

什么是release (发行版)

  • release是一个软件的发布版本,可以包含软件的源代码,二进制文件,文档等等。

  • 你可以在release里面发布软件的更新。

  • 更新时候一定要标注好版本

  • [[image/GitHub_note-9.png]]

  • 在截图中右边你可以看到tagging suggestion,让你注意版本号要写清楚

  • 在Semantic versioning(语义化的版本控制)中,版本号的格式是MAJOR.MINOR.PATCH,这个版本号是根据你的软件的变动来决定的。详情请看Semantic versioning

  • ![[image/GitHub_note-10.png]]

  • 发布即可

Package:发布npm等类型的包

![[image/GitHub_note-11.png]]
Working with the npm registry - GitHub Docs
发布npm包,使得你的项目可以被其他人直接通过npm下载使用。
这是release之后考虑的事情

GitHub Guide

问题指南 - GitHub 文档
这里面有issue和project互动教程

  • 跟着实操了一遍,感觉还是有点抽象。这种东西需要老带新,多用才会。

结语

GitHub强大全面的功能不愧是最好的项目开发网站

C++指针&*的使用

start from scratch, we already know what is variable. A variable store in memory have not only information of its value, but also its memory address.

1
int x = 5; // declare and initializa a variable

then we can use “address-of operator” - & to get the address of x!

1
int* ptr = &x //get the x's address and pass it to ptr

you may ask

  • why * ptr is a int type data
    •  you are saying that ptr is a pointer to an int.
  • where should I place the asteroid *? - Is that with end of int, or with beginning of ptr
    • only matter of style
    • However, the first style (int* ptr) is often preferred because it makes it clear that ptr is a pointer to an int. This can be especially helpful when declaring multiple pointers in a single statement:
    • int* ptr1, ptr2; // Only ptr1 is a pointer, ptr2 is an int
    • better declare one pointer per line
  • since the name of & is “address-of operator”取地址符, what is the name of * as operator
    • it is called as “dereference operator”解引用符
  • BEAWARE that & also have another way to use, which is reference
    • int &reference_value = value means give it a new name, and all operations on reference_value is same as directly on value
      You can use the pointer to access the value of x:
      1
      int value = *ptr; // Dereferencing the pointer to get the value of x

Example

example code

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main() {
int x = 10; // Declare an integer variable x and initialize it to 10
int* ptr = &x; // Declare a pointer to an integer and initialize it with the address of x

std::cout << "Value of x: " << x << std::endl; // Output the value of x
std::cout << "Address of x: " << &x << std::endl; // Output the address of x
std::cout << "Value of ptr: " << ptr << std::endl; // Output the value of ptr (address of x)
std::cout << "Value pointed to by ptr: " << *ptr << std::endl; // Output the value pointed to by ptr (value of x)

return 0;
}

result

1
2
3
4
Value of x: 10
Address of x: 0x7ffee4b3c8ac
Value of ptr: 0x7ffee4b3c8ac //ptr = &x
Value pointed to by ptr: 10 //*ptr = x

p.s. about address on a 64-bit system, a memory address might look like 0x7ffee4b3c8ac. Here’s why:

  • 0x: This prefix indicates that the number is in hexadecimal format.
  • 7ffee4b3c8ac: This is the actual address in hexadecimal. Each digit represents 4 bits, so a 64-bit address will have up to 16 hexadecimal digits.

summary

  • x is a variable that stores a value.
  • &x is the address of the variable x.
  • ptr is a pointer that stores the address of x.
  • *ptr is the value stored at the address ptr points to.

使用NexT主题时不报错但是显示错误(破案:不是最新的next官网)

Read more »
0%