Results 1 to 5 of 5

Thread: error: request for member 'show' is ambiguous w.show();

  1. #1
    Join Date
    Jun 2014
    Posts
    47
    Thanks
    6
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default error: request for member 'show' is ambiguous w.show();

    hi to all, i've Qt 5.7 in Centos 7 in VM, i am trying to build small program.
    Qt Code:
    1. #include "mymainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MyMainWindow w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    in qwidget.h :-
    Qt Code:
    1. public Q_SLOTS:
    2. // Widget management functions
    3.  
    4. virtual void setVisible(bool visible);
    5. void setHidden(bool hidden);
    6. void show(); // <-- here is showing error
    7. void hide();
    8.  
    9. void showMinimized();
    10. void showMaximized();
    11. void showFullScreen();
    12. void showNormal();
    13.  
    14. bool close();
    15. void raise();
    16. void lower();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error: request for member 'show' is ambiguous w.show();

    Hi, please show the declaration (.h file) for MyMainWindow.

    Ginsengelf

  3. #3
    Join Date
    Jun 2014
    Posts
    47
    Thanks
    6
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: error: request for member 'show' is ambiguous w.show();

    mine mymainwindow.h :-

    Qt Code:
    1. #ifndef MYMAINWINDOW_H
    2. #define MYMAINWINDOW_H
    3. //#include <QtWidgets>
    4.  
    5. #include <QMainWindow>
    6. #include <QFile>
    7. #include <QLabel>
    8. #include <QStringList>
    9. #include <QString>
    10. #include <QTableWidget>
    11.  
    12. #include "cell.h"
    13. #include "spsheetdialog.h"
    14. #include "gotocelldialog.h"
    15.  
    16. class GoToCellDialog;
    17. class FindDialog;
    18. class SPsheetDialog;
    19. class Cell;
    20.  
    21. namespace Ui {
    22. class MyMainWindow;
    23. }
    24.  
    25. class MyMainWindow : public QMainWindow, public QTableWidget
    26. {
    27. Q_OBJECT
    28.  
    29. public:
    30. explicit MyMainWindow(QWidget *parent = 0);
    31. ~MyMainWindow();
    32.  
    33. private slots:
    34. void on_actionNew_triggered();
    35.  
    36. void on_actionOpen_triggered();
    37.  
    38. void on_actionSave_triggered();
    39.  
    40. void on_actionSave_As_triggered();
    41.  
    42. void on_actionGoTo_cell_triggered();
    43.  
    44. void on_actionSort_triggered();
    45.  
    46. void on_actionAbout_triggered();
    47.  
    48. void openRecentFile();
    49.  
    50. void updateStatusBar();
    51.  
    52. void spreadsheetModified();
    53.  
    54. private:
    55. Ui::MyMainWindow *ui;
    56.  
    57. QStringList recentFiles;
    58. SPsheetDialog *spsheet;
    59. Cell *cell;
    60.  
    61. void readSettings();
    62. void writeSettings();
    63. bool okToContinue();
    64. void connectActions();
    65. void configureStatusBar();
    66.  
    67. void setCurrentFile(const QString &fileName);
    68. void updateRecentFileActions();
    69. bool loadFile(const QString &fileName);
    70. bool savefile(const QString &fileName);
    71. QString strippedName(const QString &fullFileName);
    72.  
    73. QLabel *labelLocation;
    74. QLabel *labelFormula;
    75. enum { MaxRecentFiles = 5 };
    76. QString curFile;
    77. };
    78.  
    79. #endif // MYMAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error: request for member 'show' is ambiguous w.show();

    Hi, I am not sure if it is possible to use multiple inheritance with two classes which each inherit QObject. You should probably split your widget in the part that's derived from QMainWindow, and a second widget that's derived from QTableWidget. Then use QMainWindow::setCentralWidget() to put the table widget into the main window.

    Ginsengelf

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: request for member 'show' is ambiguous w.show();

    I am not sure if it is possible to use multiple inheritance with two classes which each inherit QObject.
    It might be allowed, but is ambiguous and bad design. QMainWindow and QTableWidget both inherit from QWidget (and QObject) so every call to a QWidget or QObject method is ambiguous - as the OP's error demonstrates. Does his code want to call the show() method for the QWidget that QMainWindow is derived from, or the show() method for the QWidget that QTableWidget is derived from? The compiler can't tell when there is a common base class for two different inheritance trees.

    Even if the code qualified the call to show with one of the two base classes, it probably still wouldn't work correctly because the show() method for -both- base classes needs to be called in order to correctly layout the geometry of the two widgets. Bad design.

    Not only that, but this model violates the C++ "Is-A" convention: MyMainWindow is -not- a QTableWidget, it is-a QMainWindow. It -uses- a QTableWidget, so the design should use the "composition" convention to create a main window that is "composed" of menus, tool bars, status bars, dock windows, and a table widget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 18th October 2013, 18:15
  2. Rquest for member show() is ambiguous
    By Anshuman in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2011, 15:16
  3. Replies: 3
    Last Post: 12th July 2010, 14:12
  4. error: request for member `ok' in `xxx
    By intek in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2009, 22:16
  5. Replies: 5
    Last Post: 29th January 2006, 18:00

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.