Questions about (Functions Communications & Functionality)
-
i have some questions so please endure a newbie a bit
- i made two push buttons, one for open file dialog & the other for processing the file been selected by first push button
the problem is that i can't get the file path in the processing file function
void MainWindow::on_pb01_clicked() { QString k01 = QFileDialog::getOpenFileName(this, "Open File", "/media/user/OS Center/"); QFile k02(k01); } void MainWindow::on_pb02_clicked() { QString h02 = h01; ui->lineEdit->setText(h02); }
i tried many ways like via parameters & pointers but no luck
is there a way to get file path from ANOTHER function ?-
How to Link two Functions in Qt (e.g. i want to use variable or whatever from another function) ?
-
i want to capture objects in Qt & C++, like in Ruby
you can assign anything to Variables like:
QPushButton in Ruby would be likeL1 = ui->pushButton_1
and you will deal with the variable L1 from now on
soui->lineEdit->setText("Hello")
would beL1.setText("Hello")
orif (L1 == L2)
not like Qt where you always have to write the full object path -
i need you to guide me about Signals & Slots & using function's parameters in generals
i want to increase my knowledge about those things but i can't no matter how much i read Qt Docs, cuz i'm trying from 4 months now but can't wrap my head around it
thank you
- i made two push buttons, one for open file dialog & the other for processing the file been selected by first push button
-
1 - Add a member variable to "MainWindow" called, for example, "filePath". Assign the result of getOpenFileName to this variable. Also, The QFile you have there isn't opened and even if it had have been opened it would have been closed at the end of "on_pb01_clicked" when it was destroyed. The variable "filePath" is accessible in all member functions, therefore it is accessible in "on_pb02_clicked" e.g. ui->lineEdit->setText("you are working on the file " + filePath);
2 - This is explained above. The object (MainWindow) is the shared environment
3 - You can do this and it is even easier with C++11 the code is "auto L1 = ui->pushButton_1;"
4 - I don't know where to start with this one! Sorry! Signals are "emitted" from one QObject and, if connected, are received by a slot in another QObject (or the same one if you want to do that). The parameters passed into the "emit" will arrive at the slot function on the other side of the connection.
The signal/slot mechanism is a lot like calling a function BUT has a lot of extra functionality, notably the event queue. That is they can be queued.
Lastly, to save yourself from going mad I would recommend you use meaningful variable names. A program full of "h02, k01, pb01" will drive you mad. Worse than that it will drive your friends and colleagues insane!
-
Hi and welcome to devnet,
To add to @matthew-kuiash and based on your questions I'd recommend also taking the time to read a good C++ book. Qt is not a language, it's a C++ based framework and you really should get accustomed to it first.
-
@matthew.kuiash
thank you very much matthew your explanation about Signals & Slots is wonderful
i understand it too clearly now
also thank you for the rest of your points
i will try hard to focus on C++ fundamentals -
@SGaist
thank you SGaist for your kind replay
honestly all the tense & anxiety & obsecurity is gone thanks to matthew & you
i know now what to focus on & what's the matter with Qt
Qt is uses RAW C++ codes & don't hide any mechanism from the user
hence they required you to communicate with it in RAW format codes
it's really helpful to talk with experts ^_^