Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Questions about (Functions Communications & Functionality)
QtWS25 Last Chance

Questions about (Functions Communications & Functionality)

Scheduled Pinned Locked Moved Solved General and Desktop
objectsfunctionssignal & slotparameters
5 Posts 3 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A7lam Lover
    wrote on 9 Feb 2017, 15:51 last edited by A7lam Lover 2 Sept 2017, 15:52
    #1

    i have some questions so please endure a newbie a bit

    1. 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 ?

    1. How to Link two Functions in Qt (e.g. i want to use variable or whatever from another function) ?

    2. i want to capture objects in Qt & C++, like in Ruby
      you can assign anything to Variables like:
      QPushButton in Ruby would be like L1 = ui->pushButton_1
      and you will deal with the variable L1 from now on
      so ui->lineEdit->setText("Hello") would be L1.setText("Hello")
      or if (L1 == L2)
      not like Qt where you always have to write the full object path

    3. 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

    M 1 Reply Last reply 9 Feb 2017, 16:06
    0
    • A A7lam Lover
      9 Feb 2017, 15:51

      i have some questions so please endure a newbie a bit

      1. 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 ?

      1. How to Link two Functions in Qt (e.g. i want to use variable or whatever from another function) ?

      2. i want to capture objects in Qt & C++, like in Ruby
        you can assign anything to Variables like:
        QPushButton in Ruby would be like L1 = ui->pushButton_1
        and you will deal with the variable L1 from now on
        so ui->lineEdit->setText("Hello") would be L1.setText("Hello")
        or if (L1 == L2)
        not like Qt where you always have to write the full object path

      3. 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

      M Offline
      M Offline
      matthew.kuiash
      wrote on 9 Feb 2017, 16:06 last edited by matthew.kuiash 2 Sept 2017, 16:07
      #2

      @A7lam-Lover

      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!

      The legendary cellist Pablo Casals was asked why he continued to practice at age 90. "Because I think I'm making progress," he replied.

      A 1 Reply Last reply 10 Feb 2017, 18:26
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 9 Feb 2017, 22:44 last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 10 Feb 2017, 18:37
        0
        • M matthew.kuiash
          9 Feb 2017, 16:06

          @A7lam-Lover

          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!

          A Offline
          A Offline
          A7lam Lover
          wrote on 10 Feb 2017, 18:26 last edited by A7lam Lover 2 Oct 2017, 18:40
          #4

          @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

          1 Reply Last reply
          0
          • S SGaist
            9 Feb 2017, 22:44

            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.

            A Offline
            A Offline
            A7lam Lover
            wrote on 10 Feb 2017, 18:37 last edited by A7lam Lover 2 Oct 2017, 18:48
            #5

            @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 ^_^

            1 Reply Last reply
            0

            5/5

            10 Feb 2017, 18:37

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved