PDA

View Full Version : Tabs communication



therealjag
18th April 2006, 16:11
hey there, i have created 4 tabs in my program but they dont seem to communicate with each other by this i mean like i have this method in my third tab:



int DesignTab::tariffReturn()
{
return tariff1->currentIndex();
}


but when i try calling it from my 4th tab using DesignTab.tariffReturn( ) it gives an error when compiling saying the following:

"expected primary expression before '.' token"

does anyone know how i can call this method? or pass the value into my last tab?

jacek
18th April 2006, 16:27
Could you post the line in which this error occurs?

therealjag
18th April 2006, 17:06
yeah sure here it is:



if(DesignTab.tariffReturn() == 5) //period of rental is 5 year
{
cYear5->setText("");
}

Chicken Blood Machine
18th April 2006, 18:00
Is DesignTab a pointer? show how it is declared.

therealjag
18th April 2006, 18:29
design tab is just the name of the tab constructor - heres me header file below:



class CreatorTab : public QWidget
{
Q_OBJECT

public:
CreatorTab(const QFileInfo &fileInfo, QWidget *parent = 0);

private:
Drawer *draw;

};


class DemandsTab : public QWidget
{
Q_OBJECT


public:
DemandsTab(const QFileInfo &fileInfo, QWidget *parent = 0);



private slots:

void obtain_values(QTableWidgetItem *items);
void random();
void tableSize();

private:

void randGen(QTableWidgetItem *items);
void changeSize(QTableWidgetItem *items);

QTableWidget *demands;

};


class DesignTab : public QWidget
{
Q_OBJECT

public:
DesignTab(const QFileInfo &fileInfo, QWidget *parent = 0);


private slots:
void network_cost();
void tariffChosen();


private:
void n_cost();
int BTSelected();
int FranceSelected();
int BelgSelected();
int ItaliaSelected();

int BTPath();
int FrancePath();
int BelgPath();
int ItaliaPath();

int tariffReturn();

int isChecked;
QLineEdit *display;
QLineEdit *display2;
QLineEdit *display3;

QComboBox *tariff1;

QTableWidget *tariff;

QLabel *belgNote;

QRadioButton *radio1;
QRadioButton *radio2;
};


class PriceTab : public QWidget
{
Q_OBJECT

public:
PriceTab(const QFileInfo &fileInfo, QWidget *parent = 0);

private slots:
void rentalCost();
void priceSlot();


private:

QLabel *price;

QLineEdit *initialCost;
QLineEdit *cYear1, *cYear2, *cYear3, *cYear4, *cYear5;
QLineEdit *rYear1, *rYear2, *rYear3, *rYear4, *rYear5;


};


class TabDialog : public QDialog
{
Q_OBJECT

public:
TabDialog(const QString &fileName, QWidget *parent = 0);



private:
QTabWidget *tabWidget;

void createActions();
void createMenu();
};




#endif

Chicken Blood Machine
18th April 2006, 18:47
Well thats the problem. You can't call a member function on the class name. You must have an instance of the class. Your code should be:


// Actually create the tab somewhere
DesignTab tab = new DesignTab(...);
...
if (tab->tariffReturn() == 5) //period of rental is 5 year
{
cYear5->setText("");
}

therealjag
18th April 2006, 19:19
cheers mate ur a life saver, i tried doing that before aswell but i guess my syntax was wrong!