QVector<QPushButton*> buttonList;
global variable
void SeatReservImpl::selectSeat(){
select seat from the gui which are pushbutton
QPushButton* clickedButton= (QPushButton*)(sender());
select the clicked button
buttonList.insert(clickedButton);
add to the list but gives the error:no matching function for call to QVector::insert(QPushButton*&)
}
void SeatReservImpl::buyTicket(){
buy selected seats when pressed buy button
for ( pb=buttonList.first(); pb != 0; pb=buttonList.next() )
{
pb->setPalette(QPalette(QColor(255,0,0)));
change the color of the buttons
}
The problem is; the code is wrong and do not know how to fix them and the thing I want to do is how can I add the clicked pushbuttons to a QVector or Qlist and how to use the list or vector and reach the saved button inside the list
Edit:
Here is my code so far:
#include "SeatReservImpl.h"
#include <qmessagebox.h>
#include <stdio.h>
#include <SeatReserv.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qbuttongroup.h>
#include <qbutton.h>
#include <qobject.h>
#include <qwidget.h>
#include <qcolor.h>
#include <qpalette.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <qlist.h>
#include <qvector.h>
using namespace std;
QString slcSeat[10];
int i;
QList<QPushButton*> buttonList;
void SeatReservImpl::selectSeat()
{
QString slcSeat[10];
QPushButton* clickedButton = (QPushButton*)(sender());
QString buttName=clickedButton->name();
buttonList.append(clickedButton);
slcSeat[i]=buttName;
i++;
clickedButton->setPalette(QPalette(QColor(174,0,255)));
}
void SeatReservImpl::buyTicket(){
FILE *pfile;
char status[2];
int m;
int flag=0;
QString buttName,buttName1;
for(m=0;m<i;m++){
buttName=slcSeat[m];
system("wget -O status.txt http://embsys.heliohost.org/find.php?Seat="+buttName);
pfile=fopen("status.txt","r+");
fgets(status,sizeof status,pfile);
if(strcmp(status,"0")!=0)
flag=1;
}
if(flag){
QMessageBox::information( this, "", "You Have the Seats", QMessageBox::Ok );
QListIterator<QPushButton*> iter(buttonList);
while (iter.hasNext()) {
QPushButton *pb = iter.next();
pb->setPalette(QPalette(QColor(255,0,0)));
system("wget http://embsys.heliohost.org/buy.php?Seat="+buttName);
}
}else{
QMessageBox::information( this, "","\t\t SORRY!!!\n One of The Seats Has Been Already Sold", QMessageBox::Ok );
}
i=0;
}
But I'm getting compiler errors:
And the errors are;
SeatReservImpl.cpp: In member function ‘virtual void SeatReservImpl::selectSeat()’:
SeatReservImpl.cpp:32: error: no matching function for call to ‘QList::append(QPushButton*&)’ ../qtopia-2.2.0-FriendlyARM/qt2/include/qlist.h:61: note: candidates are: void QList::append(const type*) [with type = QPushButton*]
SeatReservImpl.cpp: In member function ‘virtual void SeatReservImpl::buyTicket()’:
SeatReservImpl.cpp:58: error: ‘class QListIterator’ has no member named ‘hasNext’
SeatReservImpl.cpp:59: error: ‘class QListIterator’ has no member named ‘next’