Nicklax
12th November 2016, 06:10
Hello, I am having trouble passing a value from one function in Qt to another in a different form
Beastiary.cpp
void beastiary::on_listWidget_itemClicked(QListWidgetIt em *item)
{
const QString nvalue = ui->listWidget->currentItem()->text(); //Value that needs to passed
read red;
red.setModal(true);
red.exec();
red.ulk();
}
read.cpp
void read::ulk()
{
QFile file (nvalue); //needs nvalue from beastiary so it knows the name of the file to look for
if (!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning (this, "Error", "File Could not Be Opened");
}
QString line;
QTextStream in(&file);
while (!in.atEnd())
{
line = in.readLine();
ui->lineEdit_name_r->setText(ui->lineEdit_name_r->text()+line);
qDebug() <<line;
}
}
The variable nvalue must be obtained in beastiary.cpp but is needed in read.cpp and im not sure of how to pass the variable to read from beastiary.
Beastiary.cpp
void beastiary::on_listWidget_itemClicked(QListWidgetIt em *item)
{
const QString nvalue = ui->listWidget->currentItem()->text(); //Value that needs to passed
read red;
red.setModal(true);
red.exec();
red.ulk();
}
read.cpp
void read::ulk()
{
QFile file (nvalue); //needs nvalue from beastiary so it knows the name of the file to look for
if (!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning (this, "Error", "File Could not Be Opened");
}
QString line;
QTextStream in(&file);
while (!in.atEnd())
{
line = in.readLine();
ui->lineEdit_name_r->setText(ui->lineEdit_name_r->text()+line);
qDebug() <<line;
}
}
The variable nvalue must be obtained in beastiary.cpp but is needed in read.cpp and im not sure of how to pass the variable to read from beastiary.