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:



    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


    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