Results 1 to 13 of 13

Thread: Abstraction required in Class

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Abstraction required in Class

    Hi..
    I am facing a rather conceptual problem,it is related to the structure of classes in my program.
    Initially i had a class derived from QGraphicsView in which i instantiate the object of another class derived from QGraphicsScene ,in the QGraphicsScene i instantiate the object of QGraphicsItem...this seems to be logical ..and it worked fine
    the thing to note is that in my QGraphicsScene class i had some button and message text displayed and a QGraphicsItem object
    but then i had to produce more abstarction in such a way that i had to develop another class in which i would put all the buttons and message text and would make an object of it in QGraphicsScene...so what i want is that that there should be two objects in my QGraphicsScene ,one that is of QGraphicsItem and the other object is my problem..because i cannot understand what my new class with button and message text should be derived from such that i can include it safely in my scene ...i dont want QGraphicsItem.for my second object...
    I hope this is well understood.
    Attached Images Attached Images
    Last edited by salmanmanekia; 3rd July 2008 at 13:16.

  2. #2
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    Actually i have made a new class for that purpose and from my part i did not have any base class for it...so that may be then i can include it in my QGraphicsScene class...but it compiles well ,but throws an error when i try to run it...i am not sure what to do ...

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    Hi ..it seemed to be a very different type of question,i was myself confused before posting to what(and how) to post exactly..but if some one understands the problem and has some advice ,please do tell me...any further queries would be also welcome

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    I have pasted my way of implementing the thing but it shows a runtime error ,what i have tried to do here is that i created a TrainingUi object which is a QGraphicsView,which instantiates QGraphicsScene object called mainScene,the mainscene is responsible for progressWidget which is QGraphicsItem and is successfully implemented and mainScene is also responsible for navigate which is a QWidget/QGraphicsWidget ,but when i create a object of navigate in my mainScene ,it throws a runtime error..

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. TrainingUI w;
    5. w.show();
    6. return a.exec();
    7. }
    8.  
    9. class TrainingUI : public QGraphicsView
    10. {
    11. public:
    12. TrainingUI();
    13. ~TrainingUI();
    14. private:
    15. MainScene *mainScn;
    16. };
    17.  
    18. class MainScene:public QGraphicsScene
    19. {
    20. public:
    21. ProgressWidget *progress;
    22. QGraphicsProxyWidget *proxy;
    23. Navigation *navigate;
    24. MainScene();
    25. };
    26.  
    27. class Navigation:public QGraphicsWidget
    28. {
    29. Q_OBJECT
    30. };
    31. class ProgressWidget:public QObject,public QGraphicsItem
    32. {
    33. Q_OBJECT
    34. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 25th July 2008 at 12:43. Reason: missing [code] tags

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Abstraction required in Class

    Quote Originally Posted by salmanmanekia View Post
    I have pasted my way of implementing the thing but it shows a runtime error
    Could you post the exact error message?

  6. #6
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    actually that problem has been solved but in the same regard i faced a new problem so instead of starting a new thread ,i will post the problem here
    this following is my implementation but it only shows an empty window
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. TrainingUI w;
    5. w.show();
    6. return a.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "MainScene.h"
    2. #include <QGraphicsView>
    3.  
    4. class TrainingUI : public QGraphicsView
    5. {
    6. Q_OBJECT
    7. public:
    8.  
    9. TrainingUI();
    10. ~TrainingUI();
    11.  
    12. private:
    13. ..
    14.  
    15. MainScene *mainScn;
    16.  
    17. ..
    18. };
    19.  
    20. TrainingUI::TrainingUI()
    21. {
    22. mainScn= new MainScene;
    23.  
    24. ..
    25. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "MainWidget.h"
    2.  
    3. #include <QGraphicsScene>
    4.  
    5.  
    6. class MainScene:public QGraphicsScene
    7. {
    8. Q_OBJECT
    9. public:
    10.  
    11. MainWidget *mainWidg;
    12. MainScene();
    13. virtual ~MainScene();
    14.  
    15. };
    16.  
    17. MainScene::MainScene()
    18. {
    19.  
    20. mainWidg = new MainWidget;
    21. addWidget(mainWidg);
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "Navigation.h"
    2.  
    3. class MainWidget:public QWidget
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. Navigation *navigate;
    9.  
    10. MainWidget();
    11. virtual ~MainWidget();
    12.  
    13. };
    14.  
    15. MainWidget::MainWidget()
    16. {
    17.  
    18. navigate = new Navigation(this);
    19. navigate->setGeometry(30,20,350,200);
    20. // naviagte->show(); // if i put this line here then it shows my navigate widget which means navigate which is a widget is doing its works
    21. }
    To copy to clipboard, switch view to plain text mode 

    i think there is some problem in between MainScene and MainWidget..
    before introducing MainWidget all the class heirarchy was same and the code inside MainWidget was in MainScene and my program ran successfully...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Abstraction required in Class

    Where do you add the scene to the view?

  8. #8
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    in the code above, i mean its in the code which i pasted in my last reply..

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Abstraction required in Class

    I don't see it.

  10. #10
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    i forgot...but its like
    Qt Code:
    1. setScene(mainScn);
    To copy to clipboard, switch view to plain text mode 
    in TrainingUI constructor..

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Abstraction required in Class

    OK, what happens if you add mainScn->addLine( 0, 0, 100, 100 ) to the TrainingUI constructor?

  12. #12
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    It works,i mean the line is shown i also changed the background of the view so for now i can see the line ,i can also see the background,but there is a grey window(empty window) over the background...in my implementation instead of grey window there should be my navigate widget...

  13. #13
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Abstraction required in Class

    its solved ,i had to add setParent the MainWidget class in the Naigation class..

Similar Threads

  1. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  2. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  3. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:05
  4. Replies: 2
    Last Post: 16th March 2007, 09:04
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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.