Nominate our 2022 Qt Champions!

QList<QPushButton *> to QList<QWidget *> impossible

  • Hello everyone !

    I'm facing a problem with my project :(
    I have a class "ElementArbo" which inherits QPushButton, and in this class I have a member QList<ElementAbo*>.
    I need to send this list to animate my buttons via another class "Animateur" which have 2 methods :

    static void translation(QWidget * const & objet, QPoint posDepart, QPoint posArrivee, int duree);
    static void translationMultiple(QList<QWidget * const> &objets, QList<QPoint> &posDepart, QList<QPoint> &posArrivee, QList<int> &duree);

    When I want to do a simple translation and send one element of my list, it works well. But when I send my list it says that "No known conversion for argument 1 from 'QList<ElementArbo*>' to 'QList<QWidget* const>&"
    I have tried a dynamic_cast but it doesn't work.

    If someone has a clue, I'll take it :)

    Thank you !

  • Moderators


    I have tried a dynamic_cast but it doesn't work.

    How did you cast it exactly?

  • @kshegunov
    Hi kshegunov !

    Here is how I did :

    Animateur::translationMultiple(dynamic_cast<QList<QWidget *>>(listFils), listPtD, listPtA, listDuree);

  • Moderators

    This will not work.QList<QWidget *> and QList<ElementArbo*> are two completely different (and unrelated classes) so there's no way you will be able to convert them like this. You can convert the elements (even without the dynamic cast) but the lists ... not happening.

    Kind regards.

  • @kshegunov
    ok thanks, I'll create a list of QWidgets and convert my element one by one
    thanks for your explainations !

Log in to reply