QVector filled with unespected numbers
Hi,
I am creating a Qt application on raspberry pi. I have a serise of checkboxes that if they are checked add their given number (1-25) to a QVector named Bank_1. I decided to display elements of the Vector in a text editor to make sure they are what I expected. They were not. When I display Bank_1[0] the result is anywhere from 24 to 495192 (or similar). Below is my code.
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QVector<int> Bank_1(QVector<int>(6));
}
void MainWindow::on_add_Relay_pushButton_clicked()
{
if(ui->bank_Select_comboBox->currentText()=="Bank 1")
{
Bank_1[0] = 1;
}
//right now I am trying to get the number to display but am still getting odd results
void MainWindow::displayVector(QVector<int> bank)
{
int i = bank[0];
ui->relay_1_lineEdit->setText(s);
}
If you need to see the .h file I can add it. Any help or explanation would be greatly appreciated.
Re: QVector filled with unespected numbers
Do you initialize the vector somewhere?
It is actually strange this works at all, the access of element in line 17 should have triggered an assert since your vector has size 0.
Cheers,
_
Re: QVector filled with unespected numbers
Quote:
Originally Posted by
cdbean04
Any help or explanation would be greatly appreciated.
The Bank_1 you declare and initialize in line 7 is a local variable defined in the constructor that will go out of scope when the constructor ends. Do you also have Bank_1 declared as a class member variable?