重新运行程序时如何查看禁用按钮被禁用

发布于 2024-11-07 03:08:18 字数 143 浏览 0 评论 0原文

我创建了很多 qpushbutton 来代表电影院的座位。用户购买座位后,我将这些座位禁用。我想做的就是看到以前禁用的按钮被禁用。我将此禁用按钮保存到 txt 文件并读取其名称,但无法将其指定为我的小部件 Qpushbuttons。有办法解决吗?

I created so much qpushbutton to represent the seat in the cinema. After user buy the seats I made these seats disabled. all I want to do is to see previously disabled button disabled. I saved this disabled button to a txt file and read their name but I could not assign it as my widget Qpushbuttons. Is there a way to solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福丶如此 2024-11-14 03:08:18

这与其说是一个按钮问题,不如说是一个数据结构问题。您应该以某种方式将您的按钮/座位连接到一个数据结构,该数据结构有助于记录可用和保留的座位。关闭程序后,会将数据写入文件或数据库,随后在打开应用程序时可以再次读取这些数据。然后,您可以再次禁用预留座位的按钮。

This is not as much a button issue as it is a data structure issue. You should somehow connect your buttons/seats to a data structure which aids in the bookkeeping of available and reserved seats. Once you close the program, you write out the data to a file or database, which you can subsequently read again when you open your application. You can then disable the buttons again of those seats which are reserved.

四叶草在未来唯美盛开 2024-11-14 03:08:18

我用 Qt 做了一些简单的例子,我希望这会对您有所帮助:

// list of all seats in order (true means seat is taken, false seat is still free)
QList<bool> seats;

// set some test values
seats.append(true);
seats.append(true);
seats.append(false);
seats.append(true);

// file where the seats will be stored
QFile file("seats.dat");

// save to file
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << seats;
file.close();

// remove all seats (just for testing)
seats.clear();

// read from file
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
in >> seats;
file.close();

// simple debug output off all seats
qDebug() << seats;

// you could set the buttons enabled state like this
QList<QPushButton*> buttons; // list of your buttons in the same order as the seat list of course
for (int i = 0; i < seats.count(); ++i)
    buttons[i]->setEnabled(!seats.at(i)); // disables all seats which are already taken

这当然只是一个简单的解决方案,使用 QDataStream 序列化完整的座位列表,但如果您是 Qt/新手,您可以尝试一下C++

I've made some quick example with Qt, I hope this will help you:

// list of all seats in order (true means seat is taken, false seat is still free)
QList<bool> seats;

// set some test values
seats.append(true);
seats.append(true);
seats.append(false);
seats.append(true);

// file where the seats will be stored
QFile file("seats.dat");

// save to file
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << seats;
file.close();

// remove all seats (just for testing)
seats.clear();

// read from file
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
in >> seats;
file.close();

// simple debug output off all seats
qDebug() << seats;

// you could set the buttons enabled state like this
QList<QPushButton*> buttons; // list of your buttons in the same order as the seat list of course
for (int i = 0; i < seats.count(); ++i)
    buttons[i]->setEnabled(!seats.at(i)); // disables all seats which are already taken

This is off course just a simple solution using a QDataStream to serialize the complete List of seats, but you can play around with this if you are new to Qt/C++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文