PYQT5 failing to concatenate strings together for folder/file directory

0

I am putting together a GUI for my program using PyQT5 and one of the actions is to get a folder directory and use it to access files. Hence, the user is required to select the folder location, and the program will access the folder to reach the files inside.

I have set it so the user selected folder is the variable called parent_path. Then parent_path2 is the next directory that is one folder deeper.

Here is my code:

class MainWindow(QMainWindow):
    def __init__(self):
        global ui
        QMainWindow.__init__(self)
        ui = uic.loadUi(_UI, self)  # Load the ui into self

    def browsebutton_clicked(self):
        dir_ = QFileDialog.getExistingDirectory(None, 'Select a folder:', 'C:\\', QFileDialog.ShowDirsOnly)
        self.lineEdit.setText(dir_)

        parent_path = self.lineEdit.text()
        print(parent_path)
        print(type(parent_path))

def sitebutton_clicked():
    input_site = ui.lineEdit_2.text()
    print(input_site)
    print(type(input_site))
    # WHY DOES IT FAIL TO ADD A STR VARIABLE TO ANOTHER STR VARIABLE?
    parent_path2 = parent_path + '/CongestionBackup_' + input_site
    print(parent_path2)

And here is the printed outputs for debugging:

C:/Users/****/Documents/JAG Projects/SCATS Congestion Monitor BACKUP/CongestionBackup
<class 'str'>
2326
<class 'str'>

Process finished with exit code -1073740791 (0xC0000409)

As you can see, if fails to get past the last 2 lines where parent_path2 is simply a concatenation for three strings which should form: C:/Users/****/Documents/JAG Projects/SCATS Congestion Monitor BACKUP/CongestionBackup/CongestionBackup_2326

I am also unsure of what that exit code means when it fails. I have tried this code in Jupyter Notebook, and the strings can be added together without any issues. I have also tried os.path.join() function, which also fails.

string
join
directory
path
pyqt5
asked on Stack Overflow Apr 3, 2020 by meronpan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0