Results 1 to 8 of 8

Thread: separate class using an interface

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default separate class using an interface

    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:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. mod3 w;
    5. w.show();
    6. return a.exec();
    7. }
    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:
    Qt Code:
    1. ...
    2. public:
    3. TWorld *W;
    4. ...
    To copy to clipboard, switch view to plain text mode 

    If the button is pushed the mathmodel class is created and calculations are executed:
    Qt Code:
    1. void mod3:: on_pushButton_clicked()
    2. {
    3. W = new TWorld();
    4. W->docalc();
    5. }
    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:
    Qt Code:
    1. void TWorld::docalc()
    2. {
    3. ... lots of calculations ...
    4. w.label->setNum(result); //doesn't work
    5. }
    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!
    Last edited by qt_gotcha; 18th February 2010 at 23:13.

Similar Threads

  1. separate a QString
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 18th July 2008, 21:50
  2. separate Qt class diagram
    By juanrb in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2008, 19:55
  3. QFtp in a separate instances
    By baray98 in forum Qt Programming
    Replies: 9
    Last Post: 11th April 2008, 05:54
  4. new QWidget in separate thread
    By magland in forum Qt Programming
    Replies: 15
    Last Post: 7th February 2008, 12:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.