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. QFileDialog and QLineEdit
QtWS25 Last Chance

QFileDialog and QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.8k 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.
  • M Offline
    M Offline
    Meugiwara
    wrote on last edited by
    #1

    Hello !

    I have 10 QLineEdit fields and 1 button which open 1 QFileDialog. When I select 1 file with the QFileDialog, the access directory is written in the first QLineEdit. After, if I want to select another file with the same button and write his access directory in the second QLineEdit, I verify if the first line is empty or not. But it doesn't work and I don't understand why. Here is my code.

    if (lined0.text().isEmpty())
            QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined0] {lined0.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (*.mp3)")));});
        else
            QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined1] {lined1.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (*.mp3)")));});
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      RamaKrishna02
      wrote on last edited by
      #2

      Hi , According ur question and sample code , this line " if (lined0.text().isEmpty()) " , is every time will check QLineEdit lined0 is empty . if lined0 is not empty .. it will go for next lined1.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Meugiwara
        wrote on last edited by
        #3

        Like this code ?

        if (!(lined0.text().isEmpty()))
                QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined1] {lined1.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (*.mp3)")));});
            else
                QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined0] {lined0.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (*.mp3)")));});
        
        1 Reply Last reply
        0
        • R Offline
          R Offline
          RamaKrishna02
          wrote on last edited by
          #4

          Can u try like this
          if (lined0.text().isEmpty())
          QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined0] {lined0.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (.mp3)")));});
          else if(!lined0.text().isEmpty()&& lined1.text().isEmpty())
          QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &lined1] {lined1.setText(QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (
          .mp3)")));});

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Your connect statement shouldn't depend on your QLineEdits state.

            Just connect the button once and then check which of the QLineEdit is empty once you return from the call to getOpenFileName.

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

            1 Reply Last reply
            2

            • Login

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