As I read in the documentation you can not return anythong from slots in pyqt, so then I decided to emit a signal from my slot but the problem is the signal is an object but I need the string of that object to put it to use. first, Am I right about the returning in pyqt slots? Second, How can I extract the string from signal object? third, is there another to that?
import sys
from PyQt6.QtCore import pyqtSignal, pyqtSlot
from PyQt6.QtWidgets import QWidget, QFileDialog, QPushButton, QVBoxLayout, QApplication
#initializing QApplication
app = QApplication(sys.argv)
class Window(QWidget):
directory = pyqtSignal(str)
def __init__(self) -> None:
super().__init__()
self.unrealEditorBtn = QPushButton("UnrealEditor Directory")
#fileDialog or selecting UnrealEditor
self.editorFileDialog = QFileDialog()
self.editorFileDialog.setFileMode(QFileDialog.FileMode.Directory)
#layout
vLayout = QVBoxLayout()
self.setLayout(vLayout)
#editor button signal
self.unrealEditorBtn.clicked.connect(self.openingFileDialog_forEditor)
#method for getting the directory of UnrealEditor.exe
@pyqtSlot(result=str)
def openingFileDialog_forEditor(self):
#this line gets the directory and put it inside self.directoy signal
self.directory.emit(str(self.editorFileDialog.getExistingDirectory(self , "PLease select the UnrealEditor.exe Directory")))
w = Window()
w.show()
sys.exit(app.exec())
As you can see in my code I want to get the existing directory to the directory class attribute then extract the string from that. Maybe I'm completely wrong or there's another way to do that.