@MEsc said in Accessing value of vector only once:
I have another function MainWindow::on_start_clicked()
When this Function get called (here via button),
values should load in vec.
QVector<QString> vec = loadfrom();
That looks like vec is a variable local to the slot attached to the button. You load it and then it is destroyed when the slot exits. If you want the vec object to have a longer lifetime then you need to arrange that. As @Christian-Ehrlicher says, making vec a private member variable of the MainWindow class is probably the right approach. So,
class MainWindow: public QMainWindow { ... private: QVector<QString> m_vec }; void MainWindow::on_start_clicked() { ... m_vec = loadfrom(); ... } void MainWindow::on_answer_returned() { ... // do stuff with m_vec ... }This is basic C++ knowledge and not Qt specific.