<?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[Slot and Qbytearray]]></title><description><![CDATA[<p dir="auto">Is it possible to define a slot qbytearray instead of void like QBytearray on_load_image()  so that it can return a qbytearray</p>
]]></description><link>https://forum.qt.io/topic/58077/slot-and-qbytearray</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 09:36:04 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/58077.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Aug 2015 18:41:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Slot and Qbytearray on Sun, 23 Aug 2015 19:38:56 GMT]]></title><description><![CDATA[<p dir="auto">Not every member function needs to be a slot. If it produces some value it doesn't sound very slottish.</p>
<p dir="auto">Consider you have a slot like <code>QByteArray MyClass::saveData()</code> and you connect it to some button:<br />
<code>connect(button, &amp;QPushButton::clicked, myObject, &amp;MyClass::saveData)</code>. You can connect it that way but where would the byte array data go? Button is certainly not gonna do anything with it.</p>
<p dir="auto">Instead something like this seems more reasonable:</p>
<pre><code>class MyClass {
   ...
public slots: //could be private or whatever
  void processPictureData() {
      savePictureData(loadPictureData());
  }
  void savePictureData(const QByteArray&amp; data) {
       /* write the data to some storage thing place */
  }

public: //could be private or whatever, but it's not a slot
  QByteArray loadPictureData() { // it could even be made static member to allow greater reusability
     /* do what you did and return the data */
  }
}
</code></pre>
<p dir="auto">Now you have a nice modular design, each piece of functionality reusable in isolation and hermetic.<br />
You can connect either of the slots to some signal.</p>
<p dir="auto">Btw. as the help in the footer suggests please use ``` around your code, not @.</p>
]]></description><link>https://forum.qt.io/post/287541</link><guid isPermaLink="true">https://forum.qt.io/post/287541</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 23 Aug 2015 19:38:56 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Qbytearray on Sun, 23 Aug 2015 19:17:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-kawa">@<bdi>Chris-Kawa</bdi></a><br />
I have 2 private slots. One to load a picture and the second one to save picture and details in my database.<br />
Load picture<br />
@fileName = QFileDialog::getOpenFileName(this,<br />
"Select image",<br />
".",<br />
"File (*.png)");<br />
ui-&gt;imageDisplay3-&gt;setPixmap(QPixmap(fileName));<br />
//QFileInfo fi(fileName);<br />
QApplication::processEvents();<br />
this-&gt;adjustSize();<br />
QFile file(fileName);<br />
if (!file.open(QIODevice::ReadOnly)) return;<br />
QByteArray byteArray = file.readAll();<br />
@<br />
I want to return byteArray so I could save it in the second slot</p>
]]></description><link>https://forum.qt.io/post/287539</link><guid isPermaLink="true">https://forum.qt.io/post/287539</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 23 Aug 2015 19:17:00 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Qbytearray on Sun, 23 Aug 2015 18:46:13 GMT]]></title><description><![CDATA[<p dir="auto">Well yes, but return it to where? When you make a <code>connect</code> nobody is expecting a return value and nobody would consume it.<br />
In design terms slots are listeners (or callbacks or whatever you call that) that modify object state when invoked. They are not meant as a value factories.</p>
]]></description><link>https://forum.qt.io/post/287535</link><guid isPermaLink="true">https://forum.qt.io/post/287535</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 23 Aug 2015 18:46:13 GMT</pubDate></item></channel></rss>