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?
Asked
Active
Viewed 281 times
0

Cengaver
- 3
- 2
- 4
2 Answers
1
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.

Bart
- 19,692
- 7
- 68
- 77
-
I read clicked button name from a text file but can not assign as qpushbutton or qpushbutton name. it may be saved as a qpushbutton but I do not know how to do it. – Cengaver May 13 '11 at 19:44
-
Why make it difficult for yourself? What about a really simple (or simplistic) solution. Say you have 100 seats. Create two vectors. One with 100 booleans (true: reserved, false: available) and one with 100 (references to the) buttons. Seat 3 is reserved? Then set boolean 3 to true in the one vector and disable button 3 in the other one. What you save and load are the booleans (or whatever datatype you wish to use for it). Not saying this is the one/only/best way to do it, but it should get you started. – Bart May 13 '11 at 19:58
-
You are right but I do not know how to do it. :) Sorry I disturb you. – Cengaver May 13 '11 at 20:08
-
I also created QList but after closing program Qlist element are cleared so gives no reason. This will be my last comment :D – Cengaver May 13 '11 at 20:22
-
It seems to me you're perhaps biting off a bit more than you can chew. I would suggest you read up a bit on general C++ development. http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Not trying to be mean, but it will teach you all basic concepts you'll need to solve this problem. – Bart May 13 '11 at 20:50
1
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++

Xander
- 687
- 9
- 15