Re: connect two buttons...
Well you're going to have to store the file name somewhere, presumably in a private QString that both buttons have access to.
What i usually do when I'm using a button for an open file dialog is set up a QLineEdit next to it and when they select the file I populate the line edit with the filename. Then when the second button is clicked you can get the filename from the line edit.
Re: connect two buttons...
Store the file name in a member variable inside MainWindow, and read it from on_B_clicked().
Re: connect two buttons...
just for understanding: I need to set a member variable to "public:" in "Mainwindow.h"? Can it also be "private:"?
Or is it also ok to define this in mainwindow.cpp?
Added after 10 minutes:
Ok I'll try this:
QString file; //I guess this should be global?
void Mainwindow:: on_A_clicked()
{
QString file=QFiledialog::getOpenFileName(
this,
("select a file"),
"c:/qt/",
("All files (*.*)"));
}
void Mainwindow:: on_B_clicked()
{
qDebug() << file; //empty now :(
QFile file;
file.open(QIODevice::Readonly);
...
}
Do I need to set the file name to the QString file too? If yes, please give a hint how -.-
Olli
Re: connect two buttons...
Quote:
Originally Posted by
xxxollixxx
just for understanding: I need to set a member variable to "public:" in "Mainwindow.h"? Can it also be "private:"?
Yes, can be private as well. That is actually what sulliwk06 suggested.
Quote:
Originally Posted by
xxxollixxx
Or is it also ok to define this in mainwindow.cpp?
mainwindow.h inside the class declaration.
Quote:
Originally Posted by
xxxollixxx
QString file; //I guess this should be global?
Better as a member of Mainwindow
Quote:
Originally Posted by
xxxollixxx
void Mainwindow:: on_A_clicked()
{
QString file=QFiledialog::getOpenFileName(
This creates a local variable with the same name, "hiding" the variable you actually want to use
Cheers,
_