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

Basic QVector application



  • Hi,
    Trying to do a basic QVector application to populate a QListWidget.

    I have successfully populated and printed the contents of a QVector in a console app, but don't quite get it with a QtWidgets application.

    Is there something glaringly obvious that I'm doing wrong?

    Please see screenshots:

    9dcbf27e-48a8-47be-9a86-d7e660f2a0b1-image.png

    8ae25a69-e9d9-43db-a96e-65e0125466d1-image.png

    Thanks in advance.



  • @Uberlinc
    This has nothing to do with QVectors, or widgets. It's basic C++.

    At line #28MainWindow::listVector is a reference to a static member of MainWindow, which is not what you have. You need to take whatever your instance of MainWindow is, e.g. perhaps you have a MainWindow mainWindow = new MainWindow(...), and reference mainWindow->listVector.

    At line #35, there is no listVector to reference. You mean to either reference mainWindow->listVector, or void printVector is intended to be a member method of class MainWindow. Similarly for the ui.

    Forget about vectors for a while. Sort out your class/member/instance references.



  • Okay, thanks..
    I'm a bit rusty at both but trying to put it all together.


  • Lifetime Qt Champion

    @Uberlinc

    Hi
    in this case
    The main issue is that you do include loadvec/printVec as members
    but the .cpp code you show you forgot
    MainWindow:: in front so compiler thinks they are just global functions.

    Should be
    void MainWindow::loadVector() {
    ...
    }

    then it works :)


Log in to reply