A very basic question! I am porting a program from Borland builder. This is the setup: a ui interface with a button and a label. A separate clas that is a mathematical model called TWorld, doing a number of calculations. The ui is a class generated in the Eclipse IDE, the main function looks like:
int main(int argc, char *argv[])
{
mod3 w;
w.show();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
mod3 w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
where mod3 is a QWidget. Eclipse generates the necessary ui related files. The class TWorld is declared in the class mod3 as:
...
public:
TWorld *W;
...
...
public:
TWorld *W;
...
To copy to clipboard, switch view to plain text mode
If the button is pushed the mathmodel class is created and calculations are executed:
void mod3:: on_pushButton_clicked()
{
W = new TWorld();
W->docalc();
}
void mod3:: on_pushButton_clicked()
{
W = new TWorld();
W->docalc();
}
To copy to clipboard, switch view to plain text mode
at the end of the calculations the result should be displayed as the label text on the interface:
void TWorld::docalc()
{
... lots of calculations ...
w.label->setNum(result); //doesn't work
}
void TWorld::docalc()
{
... lots of calculations ...
w.label->setNum(result); //doesn't work
}
To copy to clipboard, switch view to plain text mode
this doesn't work of course because label is not part of W (TWorld) but of the interface mod3. mod3 is defined and created in the main function as "w" and only exists there it seems to me. If I make w a global variable, defined as extern in a header file with the definition in main.cpp, I get the error "QWidget: Must construct a QApplication before a QPaintDevice"
I don't understand how I can make the class TWorld "see" the interface. Probably something very simple I am overloocking!
thanks!
Bookmarks