gpt4 book ai didi

c++ - 动态创建循环对象

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:49 25 4
gpt4 key购买 nike

我想在一个循环中用 Qt 创建许多按钮。

在头文件中:

QVector<QPushButton> *btns;

在cpp文件中:

btns = new QVector<QPushButton>();
for(int i = 0; i <= 10; i++) {
btns->append(new QPushButton(QString::number(i),this));
}

我收到错误:

cannot convert argument 1 from 'QPushButton *' to 'const QPushButton &'

修复它可能不难,但我不太擅长指点。你能帮帮我吗?

最佳答案

在标题中

QVector<QPushButton*>  btns;

源码

for(int i = 0; i <= 10; i++) {
btns.append(new QPushButton(QString::number(i),this));
}

关于c++ - 动态创建循环对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36451582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com