StackedWidget will not accept a custom QWidget with addWidget
-
wrote on 28 May 2024, 14:56 last edited by
Hello,
I might be missing something crucial here. I'm trying to create multiple "views" with StackedWidget by putting my custom QWidget class inside that StackedWidget. Now I created a new class called SearchView which is supposed to go in the StackedWidget as one of the "views". The problem is that StackedWidget->addWidget will not accept it even though this SearchView is inherited from QWidget (I created the SearchWidget with Qt designer form class from QTCreator). Am I not supposed to do this? If I have missed a relevant tutorial or page I am very sorry but I could not find an answer to this problem. Thank you for your timeMainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); Ui::SearchView *search_view = new Ui::SearchView(); ui->stackedWidget->addWidget(search_view);
searchview.h looks like this
namespace Ui { class SearchView; } class SearchView : public QWidget { Q_OBJECT public: explicit SearchView(QWidget *parent = nullptr); ~SearchView(); private: Ui::SearchView *ui; void populateTable(QTableWidget *table); };
The error in question is:
mainwindow.cpp:12:34: Cannot initialize a parameter of type 'QWidget *' with an lvalue of type 'Ui::SearchView *'
qstackedwidget.h:62:28: passing argument to parameter 'w' here -
You want 'SearchView', not the uic generated class 'Ui::SearchView'
-
1/2