Results 1 to 13 of 13

Thread: QMainWindow - issue

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QMainWindow - issue

    Hello forum

    I have subclass the QMainWindow and it contains another widget as a central widget. The size of the central widget depends on the size of the widget. I am trying to set the widget size inside the constructor of the subclassed QMainWindow.


    Qt Code:
    1. //GETTING ERROR ON THE FOLLOWING TWO LINES
    2. int width = sizeHint().width();
    3. int height = sizeHint().height();
    4.  
    5. //set width and height of the glwindow - WHICH IS THE WIDGET OF ANOTHER TYPE
    6. m_glWindow->width->setValue(width);
    7. m_glWindow->height->setValue(height);
    8.  
    9. setCentralWidget(m_glWindow);
    To copy to clipboard, switch view to plain text mode 


    The error that i got is :


    Qt Code:
    1. H3DMainWindow.cpp:24: warning: when initialized here
    2. H3DMainWindow.cpp:52: error: request for member ‘width’ is ambiguous
    3. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qpaintdevice.h:91: error: candidates are: int QPaintDevice::width() const
    4. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:1026: error: int QWidget::width() const
    5. /usr/local/include/H3D/H3DWindowNode.h:267: error: std::auto_ptr<H3D::SFInt32> H3D::H3DWindowNode::width
    6. H3DMainWindow.cpp:53: error: request for member ‘height’ is ambiguous
    7. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qpaintdevice.h:92: error: candidates are: int QPaintDevice::height() const
    8. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:1029: error: int QWidget::height() const
    9. /usr/local/include/H3D/H3DWindowNode.h:273: error: std::auto_ptr<H3D::SFInt32> H3D::H3DWindowNode::height
    10. H3DMainWindow.cpp: At global scope:
    11. H3DMainWindow.cpp:369: warning: unused parameter ‘fileName’
    12. make: *** [H3DMainWindow.o] Error 1
    13. sajjad@sajjad:~/Documents/H3DViewer$
    To copy to clipboard, switch view to plain text mode 



    Any hint to get around ?



    Regards
    Sajjad

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow - issue

    I think you will find that the error messages are related to the later two lines:
    Qt Code:
    1. //set width and height of the glwindow - WHICH IS THE WIDGET OF ANOTHER TYPE
    2. m_glWindow->width->setValue(width);
    3. m_glWindow->height->setValue(height);
    To copy to clipboard, switch view to plain text mode 
    and that the m_glWindow widget (a QGLWidget perhaps?) has no member variable called width/height. When the compiler looks for "width" it finds two options and doesn't know which you mean. (How you arrived at the code you wrote is a mystery to me.) I think you probably wanted:
    Qt Code:
    1. m_glWindow->resize(width, height);
    To copy to clipboard, switch view to plain text mode 

    The exercise is probably pointless because making the m_glWindow the centralWidget() will make it fill the client area of the main window anyway. It may also adjust the size hint.

  3. #3
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMainWindow - issue

    Hi

    It is not a QGLWidget subclass as you have assumed. It is a subclass of another class of a third-party API called H3DWindowNode and i checked that it has the member called width and height. To make it the central widget i have customized as follows:

    Qt Code:
    1. class MyH3DCanvasWindow : public H3D::H3DWindowNode, public QWidget
    2. {
    3. public:
    To copy to clipboard, switch view to plain text mode 


    All i want is to sent the current window's width and height to the third-party API member variable.

    Any more hint? Let me know if you need more information.


    Regards
    Sajjad


    Added after 20 minutes:


    Hi again,

    A more complete error message might help to point out the reason of the error


    Qt Code:
    1. H3DMainWindow.cpp:52: error: request for member ‘width’ is ambiguous
    2. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qpaintdevice.h:91: error: candidates are: int QPaintDevice::width() const
    3. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:1026: error: int QWidget::width() const
    4. /usr/local/include/H3D/H3DWindowNode.h:267: error: std::auto_ptr<H3D::SFInt32> H3D::H3DWindowNode::width
    5. H3DMainWindow.cpp:53: error: request for member ‘height’ is ambiguous
    6. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qpaintdevice.h:92: error: candidates are: int QPaintDevice::height() const
    7. /usr/local/Trolltech/Qt-4.8.0/include/QtGui/qwidget.h:1029: error: int QWidget::height() const
    8. /usr/local/include/H3D/H3DWindowNode.h:273: error: std::auto_ptr<H3D::SFInt32> H3D::H3DWindowNode::height
    9. H3DMainWindow.cpp: At global scope:
    10. H3DMainWindow.cpp:370: warning: unused parameter ‘fileName’
    11. make: *** [H3DMainWindow.o] Error 1
    To copy to clipboard, switch view to plain text mode 



    Thanks
    Sajjad
    Last edited by sajis997; 12th March 2012 at 07:33.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow - issue

    Excellent, it may not be a QGLWidget, but the problem is exactly as I expected.

    Your MyH3DCanvasWindow inherits a member variable called width from H3D::H3DWindowNode, and a two width() methods via QWidget. You try to use width and the compiler has three ambiguous choices. You need to rethink what you are trying to achieve by mashing the two classes together.
    Last edited by ChrisW67; 12th March 2012 at 08:12.

  5. #5
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMainWindow - issue

    Hi,

    I am trying figure out as well how to port this WxWidget application to Qt. Now i am attaching the UML diagram so that you can provide me with more insight to design is Qt equivalent.

    Please make some some to go through it. Let me explain the image again.H3DViewerWxWidget.jpeg

    Here the H3DWindowNode is the third-party class and its subclass seems to be the central widget in this wxwidget application. This subclass contains reference to other class which in turn are subclasses of wxWidget classes.


    If you need any more explanation, please shoot!

    Thanks

    Sajjad

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow - issue

    Ok but why do you insist on inheriting the H3DWindowNode class in your widget class? Why not use composition instead of inheritance? The fact that the application you are trying to port had such design doesn't mean the same design will fit a different application framework such as Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMainWindow - issue

    Hi

    Thanks for the hint. The "H3DWindowNode" is the third party API and has absolutely no relation to Qt so far. So you are suggestion the "has-a" relationship than "is-a" one. Now i have pulled out the documentation of the H3DWindowNode and it says that :


    The base class for all window nodes.

    A H3DWindowNode handles creation of windows and window properties for looking into a Scene. To implement a new window class the following functions have to be specified: swapBuffers(), initWindow(), initWindowHandler(), setFullscreen( bool fullscreen ) makeWindowActive(), setCursorType( const std::string & cursor_mode ) and getCursorForMode. For example implementation see GLUTWindow.
    The GLUTwindow is an example which subclass the H3DWindowNode.


    In that case, does the API give us the option to compose rather than inherit ?, do you see it ?


    If if e try to compose how would we do this, for example

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4.  
    5. //i need to set to set the central widget and i want to have the H3DWindowNode to be the central widget
    6. //can we make it the central widget unless we derive another class both from H3DWindowNode and QWidet
    7. }
    To copy to clipboard, switch view to plain text mode 



    I think more suggestion over this thread.


    Thanks so far

    Regards
    Sajjad

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow - issue

    Maybe we started with asking the wrong question. So let's start from scratch --- what is the base class of H3DWindowNode and where does the class come from?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow - issue

    It comes from an API called H3D. It appears to be a "widget" itself but I haven't read too much of the documentation.

  10. #10
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMainWindow - issue

    Hi

    H3DWindowNode is the base class for all window nodes. Please check the following link:

    http://www.h3dapi.org/uploads/api/H3...indowNode.html


    I really need some good design suggestion for this successful port from wxwidget to Qt.

    I need to have this class or its subclass as the central widget of the main window. Please the corresponding UML diagram in the previous post. The diagram shows how it has been implemented in WxWidget.

    I was suggested initially to have composition instead of inheritance . But i could not figure out how would it be possible with this third party API , specially once when you have to have this 3rd party class included as central widget into the main window.

    I may be looking at the from the wrong point. The WxWidget have set the subclass of H3DWindowNode as a central window implicitly.


    I shall be looking forward to more on this.


    Regards
    Sajjad

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow - issue

    Both composition and inheritance are ok here as long as you remove ambiguities from your code. Hence with inheritance instead of saying "width" you have to write "H3DWindowNode::width", etc.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMainWindow - issue

    Hi

    I have subclassed from both H3DWindowNode and QWidget. The first one is because of we have to and the second one is because i wanted to have the subclass set as central widget of the main window. Now Both the class has the width and height parameter and i guess i need to be specific when it comes to changing any of its parameter. In the main window header file i have declared a reference pointer as follows:

    Qt Code:
    1. //reference to the subclass of the H3DWindowNode
    2. //please do not confuse with the glcanvas
    3. MyH3DCanvasWindow *m_glWindow;
    To copy to clipboard, switch view to plain text mode 


    And MyH3DCanvaWindow has the following structure:

    Qt Code:
    1. class MyH3DCanvasWindow : public H3D::H3DWindowNode, public QWidget
    2. {
    3. .....................
    4. .....................
    5. .....................
    6. };
    To copy to clipboard, switch view to plain text mode 


    And i want to access the width and height parameter of one of the superclasses - in this case H3DWindowNode. I tried it as follows:


    Qt Code:
    1. int w = sizeHint().width();
    2. int h = sizeHint().height();
    3.  
    4. //set width and height of the glwindow
    5.  
    6. m_glWindow->width->setValue(w);// the width is specific to H3DWindowNode - Should we put the suggested scope resolution operator before width
    7. m_glWindow->height->setValue(h);
    To copy to clipboard, switch view to plain text mode 


    I tried as follows and it compiles fine , but i do not get the aspect of it. Any explanation ?

    Qt Code:
    1. m_glWindow->H3DWindowNode::width->setValue(w);
    2. m_glWindow->H3DWindowNode::height->setValue(h);
    To copy to clipboard, switch view to plain text mode 


    Thanks a lot folks for being with me



    Regards
    Sajjad

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMainWindow - issue

    There is QWidget::width and H3DWindowNode::width thus you have to tell the compiler which one you mean. Thus the latter works and the former doesn't.

    By the way, inherit from QWidget first and then from H3D::H3DWindowNode. moc is picky about the inheritance order so if you decide to add signals or slots to your class, you'll have problems with wrong ordering.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 6
    Last Post: 13th November 2011, 09:31
  2. Replies: 3
    Last Post: 13th November 2011, 08:12
  3. Replies: 2
    Last Post: 29th June 2011, 15:45
  4. Replies: 1
    Last Post: 28th October 2008, 16:29
  5. QMainWindow Maximization Issue
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 15th March 2007, 13:30

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.