Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Basic question - What am I doing wrong here?



  • Hi,

    Still got my training wheels on.
    I don't know why it won't recognize the objects listWidget and each of the numerically named ones - they are objects defined within the GUI form.

    The functions printlist() and setNumbers() are both declared in the mainwindow.h.
    For some reason, they work fine if I place the code in the MainWindow constructor, but if I put them into a function and call them, it doesn't recognize them.
    I've tried preceding them with ui-> as well, but then it complains it doesn't recognise 'ui'.

    Any hints?
    Thanks.

    0e218528-bdc3-4050-90fe-e18862205f59-image.png


  • Qt Champions 2017

    printList(..) & setNumbers(..) are not method of your class MainWindow. Move those methods as class methods. It should work.



  • This is how they were declared in MainWindow.h

    71cd26c0-08e2-4e5b-81fe-625179d3059c-image.png

    I don't understand where I should move them to or declare them so that they can be encapsulated in their own function.

    Can you please explain?

    Thanks.



  • You need to implement your Methode directly. Just change the Code in your cpp file to
    void```
    void Mainwindow::



  • You need to implement your Methode correctly. Just change the Code in your cpp file to

    void  Mainwindow::printList 
    And 
    void Mainwindow::setNumbers
    


  • Thank you.
    That worked!


Log in to reply