<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TypeError: unbound method QFileDialog.selectedFiles() needs an argument]]></title><description><![CDATA[<p dir="auto">I'm trying to make a file opening system using a QFileDialog, but when I try to get the selected files from it it throws a TypeError, despite the fact that nowhere in any documentation does this method seem to take an argument.<br />
Here is the relevant portion of my code:</p>
<pre><code>def openFile():
    getFile = QtWidgets.QFileDialog
    getFile.getOpenFileName(None, "Open Image", "~", "Image Files (*.png *.jpg *.jpeg *.gif *.webp;;Project Files (*.ifx)")
    openedFile = getFile.selectedFiles() # This is the code that throws the error


def menuTriggers(button):
    if button.objectName() == "actionOpen":
        openFile()

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = uiLoader.load(mainWindow)
    help = QtWidgets.QMenuBar
    window.show()
    help = window.menubar.triggered.connect(menuTriggers)
    sys.exit(app.exec())
</code></pre>
<p dir="auto">I tried using getFile variable as the argument, however that returned the error <code>TypeError: descriptor 'selectedFiles' for 'PySide6.QtWidgets.QFileDialog' objects doesn't apply to a 'Shiboken.ObjectType' object</code><br />
I also noticed that png files do not show up in the file dialog despite being in my code<br />
This code uses PySide6</p>
]]></description><link>https://forum.qt.io/topic/164903/typeerror-unbound-method-qfiledialog.selectedfiles-needs-an-argument</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 20:46:23 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164903.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Jul 2026 06:47:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 11:43:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said in <a href="/post/839232">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<pre><code>getFile = QtWidgets.QFileDialog # Parenthesis are missing here
</code></pre>
<p dir="auto">Your getFile object is not an instance of QFileDialog as you are missing the parenthesis. In this case, it's just an other name for QFileDialog.</p>
</blockquote>
<p dir="auto">I am not sure my esteemed colleague, <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a>, looked closely enough at exactly what you have written :)</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/samuraidestroy">@<bdi>SamuraiDestroy</bdi></a><br />
You were not necessarily missing parentheses on <code>getFile = QtWidgets.QFileDialog</code> --- it depends which subsequent line you look at.  It is correct for the <code>getFile.getOpenFileName()</code> statement but wrong for the <code>getFile.selectedFiles()</code> one.</p>
<p dir="auto">You have a problem here with your attempted code.  <code>QtWidgets.QFileDialog.getOpenFileName()</code> is a <em>static</em>  method (see <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.getOpenFileName" target="_blank" rel="noopener noreferrer nofollow ugc">the docs</a>) while <code>QtWidgets.QFileDialog.selectedFiles()</code> is an <em>instance</em> method (see <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.selectedFiles" target="_blank" rel="noopener noreferrer nofollow ugc">the docs</a>).  This means you cannot use them together, they do not work on the same object.  <code>selectedFiles()</code> will never look at or see what has happened in the <code>getOpenFileName()</code> call.</p>
<p dir="auto">Are you wanting the user to open a single file or multiple files?  If we assume single file then you do not need <code>selectedFiles()</code> at all and can use the simple static method:</p>
<pre><code>(openedFile, filter) = QtWidgets.QFileDialog.getOpenFileName(None, "Open Image", "~", "Image Files (*.png *.jpg *.jpeg *.gif *.webp;;Project Files (*.ifx)")
</code></pre>
<p dir="auto">The static <code>getOpenFileName()</code> puts up the dialog, waits for the user to select and press a button, and returns the (single) file selected (I think the empty string if the user presses <strong>Cancel</strong>, so you should check for that).  Note that the the way the Python <code>getOpenFileName()</code> works, unlike the C++ one, is that it returns a <em>two element list</em>: the first element is the file selected and the second element is the filter chosen by the user, which you are rarely interested in.  [Btw your <code>Image files</code> string clearly looks wrong --- count the parentheses --- so that may be interfering with its filter behaviour.]</p>
<p dir="auto">If you really want more than that, such as the ability to return multiple files selected, you cannot use one of the static methods, you need to use an instance method to do the whole lot.  Something like:</p>
<pre><code>dialog = QtWidgets.QFileDialog()
dialog.setWindowTitle("Open Image")
dialog.setDirectory("~")    # if "~" works, else path to home directory
dialog.setFilter("Image Files (*.png *.jpg *.jpeg *.gif *.webp);;Project Files (*.ifx)")
dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles)
openedFiles = []
if dialog.exec():
    openedFiles = dialog.selectedFiles()
</code></pre>
<p dir="auto">More complicated, and the sort of thing which the static <code>getOpenFileName()</code> does internally.</p>
<p dir="auto">I suspect you do not want multiple files selected and need only the static code per the first example.</p>
<p dir="auto">P.S.<br />
I just noticed that even if you do want multiple files selected there is actually <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.getOpenFileNames" target="_blank" rel="noopener noreferrer nofollow ugc">a static function for that</a> too:</p>
<pre><code>(openedFiles, filter) = QtWidgets.QFileDialog.getOpenFileNames(None, "Open Image", "~", "Image Files (*.png *.jpg *.jpeg *.gif *.webp);;Project Files (*.ifx)")
</code></pre>
<p dir="auto">Notice <code>getOpenFileNames()</code> plural.  So you could use that instead of the instance method.  But I have left the instance stuff in, it can be useful in various circumstances where static methods do not do quite do what you want.</p>
]]></description><link>https://forum.qt.io/post/839236</link><guid isPermaLink="true">https://forum.qt.io/post/839236</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 20 Jul 2026 11:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 11:36:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/839236">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<p dir="auto">[Btw your Image files string clearly looks wrong --- count the parentheses --- so that may be interfering with its filter behaviour.]<br />
Ah, I somehow missed that before. Yep, adding the extra ) fixed it.</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/839236">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<p dir="auto">I just noticed that even if you do want multiple files selected there is actually a static function for that too:</p>
</blockquote>
<p dir="auto">This works perfectly and does exactly what I was trying to do, thank you</p>
]]></description><link>https://forum.qt.io/post/839241</link><guid isPermaLink="true">https://forum.qt.io/post/839241</guid><dc:creator><![CDATA[SamuraiDestroy]]></dc:creator><pubDate>Mon, 20 Jul 2026 11:36:19 GMT</pubDate></item><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 09:19:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/839236">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said in <a href="/post/839232">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<pre><code>getFile = QtWidgets.QFileDialog # Parenthesis are missing here
</code></pre>
<p dir="auto">Your getFile object is not an instance of QFileDialog as you are missing the parenthesis. In this case, it's just an other name for QFileDialog.</p>
</blockquote>
<p dir="auto">I am not sure my esteemed colleague, <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a>, looked closely enough at exactly what you have written :)</p>
</blockquote>
<p dir="auto">I did but was way too short on my answer :-)<br />
I somehow forgot to add the static function bit although I had it mind.</p>
]]></description><link>https://forum.qt.io/post/839239</link><guid isPermaLink="true">https://forum.qt.io/post/839239</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 20 Jul 2026 09:19:27 GMT</pubDate></item><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 11:43:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said in <a href="/post/839232">TypeError: unbound method QFileDialog.selectedFiles() needs an argument</a>:</p>
<blockquote>
<pre><code>getFile = QtWidgets.QFileDialog # Parenthesis are missing here
</code></pre>
<p dir="auto">Your getFile object is not an instance of QFileDialog as you are missing the parenthesis. In this case, it's just an other name for QFileDialog.</p>
</blockquote>
<p dir="auto">I am not sure my esteemed colleague, <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a>, looked closely enough at exactly what you have written :)</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/samuraidestroy">@<bdi>SamuraiDestroy</bdi></a><br />
You were not necessarily missing parentheses on <code>getFile = QtWidgets.QFileDialog</code> --- it depends which subsequent line you look at.  It is correct for the <code>getFile.getOpenFileName()</code> statement but wrong for the <code>getFile.selectedFiles()</code> one.</p>
<p dir="auto">You have a problem here with your attempted code.  <code>QtWidgets.QFileDialog.getOpenFileName()</code> is a <em>static</em>  method (see <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.getOpenFileName" target="_blank" rel="noopener noreferrer nofollow ugc">the docs</a>) while <code>QtWidgets.QFileDialog.selectedFiles()</code> is an <em>instance</em> method (see <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.selectedFiles" target="_blank" rel="noopener noreferrer nofollow ugc">the docs</a>).  This means you cannot use them together, they do not work on the same object.  <code>selectedFiles()</code> will never look at or see what has happened in the <code>getOpenFileName()</code> call.</p>
<p dir="auto">Are you wanting the user to open a single file or multiple files?  If we assume single file then you do not need <code>selectedFiles()</code> at all and can use the simple static method:</p>
<pre><code>(openedFile, filter) = QtWidgets.QFileDialog.getOpenFileName(None, "Open Image", "~", "Image Files (*.png *.jpg *.jpeg *.gif *.webp;;Project Files (*.ifx)")
</code></pre>
<p dir="auto">The static <code>getOpenFileName()</code> puts up the dialog, waits for the user to select and press a button, and returns the (single) file selected (I think the empty string if the user presses <strong>Cancel</strong>, so you should check for that).  Note that the the way the Python <code>getOpenFileName()</code> works, unlike the C++ one, is that it returns a <em>two element list</em>: the first element is the file selected and the second element is the filter chosen by the user, which you are rarely interested in.  [Btw your <code>Image files</code> string clearly looks wrong --- count the parentheses --- so that may be interfering with its filter behaviour.]</p>
<p dir="auto">If you really want more than that, such as the ability to return multiple files selected, you cannot use one of the static methods, you need to use an instance method to do the whole lot.  Something like:</p>
<pre><code>dialog = QtWidgets.QFileDialog()
dialog.setWindowTitle("Open Image")
dialog.setDirectory("~")    # if "~" works, else path to home directory
dialog.setFilter("Image Files (*.png *.jpg *.jpeg *.gif *.webp);;Project Files (*.ifx)")
dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles)
openedFiles = []
if dialog.exec():
    openedFiles = dialog.selectedFiles()
</code></pre>
<p dir="auto">More complicated, and the sort of thing which the static <code>getOpenFileName()</code> does internally.</p>
<p dir="auto">I suspect you do not want multiple files selected and need only the static code per the first example.</p>
<p dir="auto">P.S.<br />
I just noticed that even if you do want multiple files selected there is actually <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.QFileDialog.getOpenFileNames" target="_blank" rel="noopener noreferrer nofollow ugc">a static function for that</a> too:</p>
<pre><code>(openedFiles, filter) = QtWidgets.QFileDialog.getOpenFileNames(None, "Open Image", "~", "Image Files (*.png *.jpg *.jpeg *.gif *.webp);;Project Files (*.ifx)")
</code></pre>
<p dir="auto">Notice <code>getOpenFileNames()</code> plural.  So you could use that instead of the instance method.  But I have left the instance stuff in, it can be useful in various circumstances where static methods do not do quite do what you want.</p>
]]></description><link>https://forum.qt.io/post/839236</link><guid isPermaLink="true">https://forum.qt.io/post/839236</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 20 Jul 2026 11:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 07:24:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Thank you so much, that fixed the error, however when I print out the openedFile variable, it only prints an empty list regardless of what was selected. The issue of .png files not showing up is still present however.</p>
]]></description><link>https://forum.qt.io/post/839233</link><guid isPermaLink="true">https://forum.qt.io/post/839233</guid><dc:creator><![CDATA[SamuraiDestroy]]></dc:creator><pubDate>Mon, 20 Jul 2026 07:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to TypeError: unbound method QFileDialog.selectedFiles() needs an argument on Mon, 20 Jul 2026 07:10:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<pre><code>    getFile = QtWidgets.QFileDialog # Parenthesis are missing here
</code></pre>
<p dir="auto">Your <code>getFile</code> object is not an instance of <code>QFileDialog</code> as you are missing the parenthesis. In this case, it's just an other name for <code>QFileDialog</code>.</p>
]]></description><link>https://forum.qt.io/post/839232</link><guid isPermaLink="true">https://forum.qt.io/post/839232</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 20 Jul 2026 07:10:30 GMT</pubDate></item></channel></rss>