Hello, I am having trouble passing a value from one function in Qt to another in a different form
Beastiary.cpp
{
const QString nvalue
= ui
->listWidget
->currentItem
()->text
();
//Value that needs to passed read red;
red.setModal(true);
red.exec();
red.ulk();
}
void beastiary::on_listWidget_itemClicked(QListWidgetItem *item)
{
const QString nvalue = ui->listWidget->currentItem()->text(); //Value that needs to passed
read red;
red.setModal(true);
red.exec();
red.ulk();
}
To copy to clipboard, switch view to plain text mode
read.cpp
void read::ulk()
{
QFile file (nvalue
);
//needs nvalue from beastiary so it knows the name of the file to look for {
QMessageBox::warning (this,
"Error",
"File Could not Be Opened");
}
while (!in.atEnd())
{
line = in.readLine();
ui->lineEdit_name_r->setText(ui->lineEdit_name_r->text()+line);
qDebug() <<line;
}
}
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;
}
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks