Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: request for member 'show' is ambiguous w.show()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahulvishwakarma
    wrote on last edited by
    #1

    hi to all, i've Qt 5.7 in Centos 7 in VM, i am trying to build small program.
    i've Qt 5.7 in Centos 7 in VM, i am trying to build small program spreadsheet reader.

    #include "mymainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MyMainWindow w;
        w.show(); // <-- ambiguity
    
        return a.exec();
    }
    

    mine mymainwindow.h is :
    update 1:-
    i tried virtual inheritance because two headers are using same class
    class maninwindow is :-

    #ifndef MYMAINWINDOW_H
    #define MYMAINWINDOW_H
    #include <QMainWindow>
    #include <QFile>
    #include <QLabel>
    #include <QStringList>
    #include <QString>
    #include <QTableWidget>
    
    #include "cell.h"
    #include "spsheetdialog.h"
    #include "gotocelldialog.h"
    #include "sortdialog.h"
    
    class GoToCellDialog;
    class FindDialog;
    class SPsheetDialog;
    class Cell;
    class SortDialog;
    
    namespace Ui {
    class MyMainWindow;
    }
    
    class MyMainWindow : public QMainWindow, public virtual QTableWidget
    {
        Q_OBJECT
    
    public:
        explicit MyMainWindow(QWidget *parent = 0);
        virtual ~MyMainWindow();
    
    private slots:
        void on_actionNew_triggered();
        void on_actionOpen_triggered();
        void on_actionSave_As_triggered();
        void on_actionGoTo_cell_triggered();
        void on_actionSort_triggered();
        void on_actionAbout_triggered();
        void openRecentFile();
        void updateStatusBar();
        void spreadsheetModified();
        bool saveAs();
        bool save();
    
    private:
        Ui::MyMainWindow *ui;
    
        enum { MaxRecentFiles = 5 };
    
        QAction *recentFileActions[MaxRecentFiles];
    
        QStringList recentFiles;
        SPsheetDialog *spsheet;
        Cell *cell;
    
        void readSettings();
        void writeSettings();
        bool okToContinue();
        void connectActions();
        void configureStatusBar();
    
        void setCurrentFile(const QString &fileName);
        void updateRecentFileActions();
        bool loadFile(const QString &fileName);
        bool saveFile(const QString &fileName);
        QString strippedName(const QString &fullFileName);
    
        QLabel *labelLocation;
        QLabel *labelFormula;
    
        QString curFile;
    };
    
    #endif // MYMAINWINDOW_H
    

    and other spreadsheet.h

    #ifndef SPSHEETDIALOG_H
    #define SPSHEETDIALOG_H
    
    #include <QDialog>
    #include <cell.h>
    #include <spsheetdialog.h>
    
    class Cell;
    class SpreadsheetCompare;
    
    namespace Ui {
    class SPsheetDialog;
    }
    
    class SPsheetDialog : public QDialog, public virtual QTabWidget
    {
        Q_OBJECT
    
    public:
        explicit SPsheetDialog(QWidget *parent = 0);
        ~SPsheetDialog();
    
        bool autoRecalculate() const { return autoRecalc; }
        void clear();
        bool readFile(const QString &fileName);
        QString currentLocation() const;
        QString currentFormula() const;
        QTableWidgetSelectionRange selectedRange() const;
        bool writeFile(const QString &fileName);
        void sort(const SpreadsheetCompare &compare);
    signals:
        void modified();
    private:
        Ui::SPsheetDialog *ui;
    public slots:
        void cut();
        void copy();
        void del();
        void paste();
        void selectCurrentRow();
        void recalculate();
        void setAutoRecalcuate();
        void findNext(const QString &str, Qt::CaseSensitivity cs);
        void findPrevious(const QString &str, Qt::CaseSensitivity cs);
    private slots:
        void somethingChanged();
    private:
        enum { MagicNumber = 0x7F51C883, RowCount = 999, ColumnCount = 26 };
    
        Cell *cell(int row, int column) const;
        QString text(int row, int column) const;
        QString formula(int row, int column) const;
    
        void setFormula(int row, int column, const QString &formula);
        bool autoRecalc;
    
    
    };
    
    class SpreadsheetCompare
    {
    public:
        bool operator()(const QStringList &row1,
                        const QStringList &row2) const;
    
        enum { KeyCount = 3 };
        int keys[KeyCount];
        bool ascending[KeyCount];
    };
    #endif // SPSHEETDIALOG_H
    i have a problem of ambiguity in show function. but i am not getting where do these  two same code ( show ) are included. Which header should i include
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      You have some very odd inheritance

      class MyMainWindow : public QMainWindow, public virtual QTableWidget

      Both are Widgets so there will be 2 shows etc.

      Also, why inherited BOTH a MainWindow and a QTableWidget ?

      Normally you just put the QTableWidget in the Mainwindow.
      (and it would be ui->tablewidget to talk to it)

      Having a window that is both a window and a TableWidget blows my brain :)

      1 Reply Last reply
      3
      • R Offline
        R Offline
        rahulvishwakarma
        wrote on last edited by
        #3

        i want to connect spreadsheet reader signal "currentCellChanged" which is signal of QTableWidget as here

        connect(spsheet, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(updateStatusBar()) );

        JonBJ 1 Reply Last reply
        0
        • R rahulvishwakarma

          i want to connect spreadsheet reader signal "currentCellChanged" which is signal of QTableWidget as here

          connect(spsheet, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(updateStatusBar()) );

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @rahulvishwakarma
          You really need to heed what @mrjj is saying, and start by rewriting/redesigning:

          Also, why inherited BOTH a MainWindow and a QTableWidget ?

          Normally you just put the QTableWidget in the Mainwindow.

          (and it would be ui->tablewidget to talk to it)

          First do that, then sort out the signals/slots, when your code will work.

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Ok normally that would be having just MainWindow derived ONLY from QMainwindow
            and then place the QTableWidget on the UI form.

            alt text

            and then in MainWindow.h define a matching slot

            class MainWindow : public QMainWindow
            {
            Q_OBJECT
            public slots:
            void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
            ...

            and the body in mainwindow.cpp

            void MainWindow::currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
            {
             // call here update statubar etc
            }
            
            

            and then in the MainWindow constructor

            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                connect(ui->tableWidget, &QTableWidget::currentCellChanged, this, &MainWindow::currentCellChanged );
            
            }
            
            
            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved