function object() { if (fileDialog.selectedNameFilter.index === 0) { console.log("PDF") return "ReadPdf.qml" } else if(fileDialog.selectedNameFilter.index === 1) { console.log("TXT") return "ReadTxt.qml" } } Loader { id: myLoader anchors.fill: parent Component.onCompleted: { squareLoader.setSource(url, { "color": "blue" } ); } } FileDialog { id: fileDialog title: "Open file" nameFilters: [ "PDF file (*.pdf)" , "TXT file (*.txt)" ] onAccepted: { // selectedFile } }