ℳ๓. Sweet 2022-04-11 17:41 采纳率: 50%
浏览 97
已结题

想用QT开发个扑克牌】小游戏,但是扑克牌的显示偶尔四张都有,偶尔缺失一两张,不知啥问题

这是未完成的UI界面(有缺失和不缺失,底下终端显示的是当前获取的随机数)

img

img

这是切换扑克图片的函数

QString poke(int num)
{
srand( (unsigned)time(NULL) ); // 设置随机序列的种子
switch(num)
{
case 1 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/14.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/27.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/40.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/53.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 2 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/15.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/28.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/41.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/54.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 3 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/16.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/29.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/42.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/55.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 4 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/17.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/30.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/43.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/56.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 5 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/18.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/31.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/44.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/57.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 6 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/19.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/32.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/45.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/58.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 7 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/20.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/33.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/46.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/59.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 8 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/21.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/34.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/47.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/60.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 9 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/22.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/35.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/48.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/61.jpg);}"};
int r = rand() % 4;
return candidates[r];
}
break;
case 10 :
{
QString candidates[] = {"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/23.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/36.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/49.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/62.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/24.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/25.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/26.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/11.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/12.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/13.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/37.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/38.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/39.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/50.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/51.jpg);}",
"QLabel{border-image: url(C:/Users/zhongzebin/Desktop/QT_practice/24_game/photo/poke/52.jpg);}"};
int r = rand() % 16;
return candidates[r];
}
break;
default:
break;

    }
}

};

请大家们看看是什么原因,每次刷新都是随机出现的。
  • 写回答

1条回答 默认 最新

  • 关注

    首先别的不说,你的函数不是所有路径都返回值,如果switch在default跳出,那么函数没有返回,不同的编译器有不同的反应,极有可能返回一个未定义的值,如果确保绝不可能在defaul跳出,那么很有可能这些文件名的文件不是全都有

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 已采纳回答 4月14日
  • 创建了问题 4月11日

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?