Results 1 to 5 of 5

Thread: QT signal, function

  1. #1
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default QT signal, function

    Hello all, im new and i want help .

    I have my function for select file :

    Qt Code:
    1. QString MainWindow::on_Browse_clicked()
    2. {
    3. QString fichier = QFileDialog::getOpenFileName(this, "Ouvrir un fichier", QString(), "Exe (*.exe)");
    4. QMessageBox::information(this, "test", "Vous avez sélectionné :\n" + fichier);
    5. QFileInfo fileInfo(fichier);
    6. QDir dir = fileInfo.dir(); // Dossier du fichier
    7. QString dirPath = fileInfo.filePath(); // Path vers le fichier
    8. QString fileName = fileInfo.fileName(); // Nom du fichier (sans le path)
    9. ui->lineEdit->setText(fichier);
    10. return fichier;
    11. }
    To copy to clipboard, switch view to plain text mode 


    And here my function for start the file :
    Qt Code:
    1. void MainWindow::on_start_clicked(QString fichier)
    2. {
    3. QString open = QDesktopServices::openUrl(QUrl(fichier,QUrl::TolerantMode));
    4. }
    To copy to clipboard, switch view to plain text mode 

    but it does not work, i have to connect my 2 buttons for get "QString fichier" variable ?
    if yes how ?
    Thanks all and sorry for my poor english !

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT signal, function

    The push button called start does not have a signal clicked() that passes a string. The automatic connection mechanism never makes the connection so the button will never trigger this code.

    You return a value from the browse slot, but this value has nowhere to go: slots cannot return values.

    You should put the browse result in a member variable and access that from the click handler to get the value.

  3. #3
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT signal, function

    thanks you, but i dont fully understand, my english is sad :s

    i have make this :
    Qt Code:
    1. QString MainWindow::on_Browse_clicked()
    2. {
    3. QString localtiondebol;
    4. QString fichier = QFileDialog::getOpenFileName(this, "Ouvrir un fichier", QString(), "Exe (*.exe)");
    5. QMessageBox::information(this, "Tipie launcher", "Vous avez sélectionné :\n" + fichier);
    6. QFileInfo fileInfo(fichier);
    7. QDir dir = fileInfo.dir(); // Dossier du fichier
    8. QString dirPath = fileInfo.filePath(); // Path vers le fichier
    9. QString fileName = fileInfo.fileName(); // Nom du fichier (sans le path)
    10. ui->lineEdit->setText(dirPath);
    11. localtiondebol = dirPath;
    12. return localtiondebol;
    13. }
    To copy to clipboard, switch view to plain text mode 

    my variable localtiondebol = the acess at the .exe, but i dont know how i can use "locationdebol" variable in my other function :

    Qt Code:
    1. void MainWindow::on_start_clicked()
    2. {
    3. QString localtiondebol;
    4. localtiondebol = on_Browse_clicked();
    5. ui->lineEdit_3->setText(localtiondebol);
    6. QDesktopServices::openUrl(QUrl(localtiondebol,QUrl::TolerantMode));
    7. }
    To copy to clipboard, switch view to plain text mode 

    i have try this
    Qt Code:
    1. localtiondebol = on_Browse_clicked();
    To copy to clipboard, switch view to plain text mode 
    but its dont work

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QT signal, function

    No offense, but this is basic C++.

    If 'localtiondebol' is meant to be set in a method and read in another, then it certainly should not be declared a a local variable in either method; it should be a non-static member of the class.

    That being said, I wonder whether you need this variable at all. If I understand correctly, the Browse button lets the user select a file in a dialog and then puts its name in a QLineEdit (more precisely, ui->lineEdit). Later on, the start button does something with a file... but what file? Is it supposed to be the file originally selected in the dialog, or the file whose name appears in ui->lineEdit, which may have been manually altered by the user? In the latter case, all you need to do is read the text from ui->lineEdit in on_start_clicked().

  5. #5
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT signal, function

    I did not know that I could retrieve the text of lineEdit.
    it work well thanks you

Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 22:36
  2. Connect two signal to function
    By updaterr in forum Qt Quick
    Replies: 1
    Last Post: 17th June 2014, 10:35
  3. Replies: 2
    Last Post: 26th October 2013, 06:40
  4. SIGNAL/SLOT Calling the same function. Possible?
    By matthieunc in forum Qt Programming
    Replies: 4
    Last Post: 29th July 2011, 00:24
  5. Emit signal from const function
    By waynew in forum Qt Programming
    Replies: 9
    Last Post: 22nd August 2010, 14:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.