I'm trying to get every CustomQWidget i added to the layout and insert them into a QVector so i can sort them.
void MainWindow::onFilenameClick()
{
QVector<CustomQWidget*> qv;
for(int i = 0; i < ui->widgets_layout->count(); i++) {
QWidget *widget = ui->widgets_layout->itemAt(i)->widget();
if(widget != nullptr) {
qv.append(widget);
}
}
std::sort(qv.begin(), qv.end(), sort_by_filename());
update_ui(qv);
}
The problem is that i keep getting the error message
no matching member function for call to 'append'
candidate function not viable: cannot convert from base class pointer 'QWidget *' to derived class pointer 'CustomQLabel *const' for 1st argument
candidate function not viable: cannot convert from base class pointer 'QWidget *' to derived class pointer 'CustomQLabel *' for 1st argument
candidate function not viable: cannot convert from base class pointer 'QWidget *' to 'const QVector<CustomQWidget *>' for 1st argument
I've already tryed to static_cast the CustomQWidget to QWidget but nothing has changed.
qv.append(static_cast<QWidget*>(widget));
And I also tried with
qv.push_back(widget);
qv.insert(i, widget);
Here's the CustomQWidget.h
class CustomQWidget : public QWidget
{
Q_OBJECT
public:
...
private:
Ui::CustomQWidget *ui;
...
};
I really don't know what to do, please help me