如何确定PyQtSignal传递给pyqtSlot的参数?以QFileSystemModel为例
关于PyQt5中QFileSystemModel的directoryLoaded信号参数传递的疑问
我正在学习Qt的Model-View架构,用PyQt5复现模型索引用法时,写出了一段可运行但不完全理解的脚本,代码如下:
def main(): app = QApplication(sys.argv) path = '/path/to/dir/' model = QFileSystemModel() model.setRootPath(path) window = QWidget() layout = QVBoxLayout(window) label = QLabel("Files and Directories:\n") layout.addWidget(label) def link_data(directory): parent_index = model.index(directory) num_rows = model.rowCount(parent_index) names = [] for row in range(num_rows): index = model.index(row, 0, parent_index) name = model.data(index) names.append(name) label.setText("Files and Directories:\n" + "\n".join(names)) # Connect the directoryLoaded signal to the link_data slot model.directoryLoaded.connect(link_data) window.setWindowTitle("File System Model Data Retrieval") window.show() sys.exit(app.exec_()) if __name__ == "__main__": main()
我注意到model.directoryLoaded.connect(link_data)会在directoryLoaded信号触发时,将模型的根路径传递给link_data槽函数的directory参数。但查看QFileSystemModel的C++文档,仅说明void QFileSystemModel::directoryLoaded(const QString &path)会在后台线程完成路径加载时触发。
我想理解link_data(directory)中的directory参数是如何被填充的,以及如何从文档中获取这类信息。
内容的提问来源于stack exchange,提问作者curioso
相关产品推荐
相关产品推荐

