layout: post
title: xtx暑假第五周日志
categories: 日志
tags:
- 日志
- 2021暑期日志
BGImage: 'https://github.xutongxin.me/https://raw.githubusercontent.com/xutongxin1/PictureBed/master/img0/uTools_1630759499350.png'
jekyll-theme-WuK:
musicid: '41631040'
第五周日志
这周仍然是三国杀,但是数模临近,要做两次模拟比赛练习,还有科三,所以时间其实挺少的
8.16
动画进行时,控件的坐标是:未知数或者很大的数
所以建议先做关于控件坐标的判断再做动画
同时,动画在用户代码执行结束前不会触发启动,换而言之不能让程序执行一个动画后根据动画的末位置来做判断
如果这样做了,你也会发现调试结果和代码执行结果更本不同
8.17
结构体数组定义
struct cardLib
{
cardSpecies Species;
string name;
int num;
int last;//洗牌前需要校验数量
};
cardLib allCardLib[100]={
{kill,"杀",5,5},
{flash,"闪",5,5},
{peach,"桃",20,20},
{impeccable,"无懈可击",20,20},
{outOfNothing,"无中生有",20,20}
};
8.18
函数重定义和重载
https://blog.csdn.net/cpp12341234/article/details/52195993
#include <iostream>
using namespace std;
class CBase
{
public:
void my(int a){
cout << "父类" << endl;
}
};
class CDerivedA : public CBase
{
public:
void my(int a ){
cout << "子类" << endl;//第一种情况,函数名,返回类型,参数都相同
}
};
int main()
{
CDerivedA ptr;
ptr.my(5);
system("pause");
return 0;
}
上面结果为调用子类成员函数输出:子类
驼峰大小写
又开始傻傻忘了
https://blog.csdn.net/K346K346/article/details/81395342
类名是大驼峰
The moc process failed to compile "SRC:/mainwindow.h"
into
"SRC:/cmake-build-debug-qt/QTCMake_autogen/EWIEGA46WW/moc_mainwindow.cpp"
我的枚举用了;作为分隔但是编译器没有报错
Allocation of incomplete type 'QTimer'
#include <QTimer>
vector playerHandHeap;结构体向量报错
原因是有一个结构体和其类型的变量名字相同
struct HandHeap
{
cardSpecies Species;
string name;
int id;
}HandHeap[108];
No matching member function for call to 'push_back'
vector<HandHeap*> playerHandHeap;
这种使用方式见https://blog.csdn.net/v_xchen_v/article/details/50926991
函数传入对象作为参数
void doJudgmentStage(Player* player);
//下面的写法是错误的,会导致传参时错误
//void doJudgmentStage(Player player);
可选参数必须放在函数传参的最后
void getPlayerHandEvent(Player* player, int num,bool type = false);
父类引用子类方法
最好就是别!
在类的外部来实现两个类之间的通信工作
然后在思考,是否必须用两个类,两个类是否必须要有继承关系
在这次写程序的时候,我一开始写的是
Player继承了MainWindows
然后MainWindows通过include player.h来创建player的对象
但是在初始化Player时也include了MainWindows.h
结果就相互引用了
重复定义问题的解决办法,multiple definition of xxxx
还是该感谢一下王汉宁师兄
最后的解决方法是
在cpp定义声明,在另一个cpp要用的时候就extern它
(8.24再记录)
其实只要在cpp或者c里定义声明就好了,其他地方一律extern
原因详解:https://blog.csdn.net/mantis_1984/article/details/53571758
那怎么写比较好呢,在面对很多个cpp都需要extern同一堆变量
我采用了把extern写在一个头文件里然后引用这个头文件
该头文件还放了struct和enum
8.22
error: jump to case label [-fpermissive]
case choosingHandTimer:
在case中定义了变量但是由于没有括号,无法确定该变量的定义域
解决方法:case下加一个括号
case choosingHeroTimer: {
vector<int> a = {1};
chooseFinish(a);
break;
}
border-image
自动缩放绘制控件背景yyds
QSS既可以用相对路径也可以用qrc路径
听说还可以用绝对路径
ui->HeroHead->setStyleSheet("border-image: url(resource/hero/28.png);");
https://www.coder.work/article/6821584
QObject::connect: Parentheses expected, signal QParallelAnimationGroup::finished in C:\GitProject\QTCMake\mainrun.cpp:18
QObject::connect: (receiver name: 'MainWindow')
connect(animeGroup, SIGNAL(finished()),this, SLOT(PrepareRoundOfGame()));
记住别漏了SIGNAL(finished())finish里的括号
跳转到 { return *(this->_M_impl._M_start + __n); }及其类似的stl文件内
检查调试器,变量观察器处是否观察了仍未出现的向量元素
8.23
Clion debug时看不到STL容器的值
https://blog.csdn.net/SSibyl/article/details/116538799
8.24
connect配lambda表达式
不能用SIGNAL(clicked())
第一个是错误示范
//connect(ui->testButton1,SIGNAL(clicked()),this,[=]{playerList[0]->getHandEvent(1);});
connect(ui->testButton1,&QPushButton::clicked,this,[=]{playerList[0]->getHandEvent(1);});
string和qstring转换
https://www.jianshu.com/p/42d343236406
string str;
QString qstr;
//从QString 到 std::string
str = qstr.toStdString();
//从std::string 到QString
qstr = QString::fromStdString(str);
Qt::UniqueConnection
类型,则只有在它不是重复的情况下才会建立连接。如果已经有重复(相同对象上完全相同的插槽的完全相同的信号),则连接将失败并且 connect 将返回false
。