<?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[How to use &quot;sigaction&quot; in Qt?]]></title><description><![CDATA[<p dir="auto">@fd  = open("/dev/hpi0",O_RDONLY);<br />
sigaction(SIGIO, sig_handler, NULL);<br />
fcntl(fd, F_SETOWN, getpid());<br />
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | FASYNC);@<br />
This can't work.<br />
How to use "sigaction" in -QT- Qt? Or, other method to achieve "soft interrupt"?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/topic/5927/how-to-use-sigaction-in-qt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 23:42:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/5927.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 May 2011 07:54:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Thu, 02 Mar 2023 05:35:50 GMT]]></title><description><![CDATA[<p dir="auto">This <a href="https://github.com/AndreiCherniaev/QCoreApplication_quit_example" target="_blank" rel="noopener noreferrer nofollow ugc">example</a> explain how to use SIGINT (terminate app using Ctrl+C).</p>
]]></description><link>https://forum.qt.io/post/749658</link><guid isPermaLink="true">https://forum.qt.io/post/749658</guid><dc:creator><![CDATA[DungeonLords]]></dc:creator><pubDate>Thu, 02 Mar 2023 05:35:50 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 22:15:19 GMT]]></title><description><![CDATA[<p dir="auto">Use the Self Pipe Trick.</p>
<p dir="auto"><a href="http://doc.qt.nokia.com/4.7/unix-signals.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.nokia.com/4.7/unix-signals.html</a></p>
<p dir="auto">Apart from this, UNIX signal handlers must be ordinary C functions (in C++ you'll need the extern C linkage).</p>
]]></description><link>https://forum.qt.io/post/88728</link><guid isPermaLink="true">https://forum.qt.io/post/88728</guid><dc:creator><![CDATA[dangelog]]></dc:creator><pubDate>Wed, 18 May 2011 22:15:19 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 21:47:04 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">It's not possible to directly call a non static member function of class through C style signal handler.  Try to delegate task of handling signal to an instance of class using a static member function. See code below for example:</p>
<p dir="auto">@<br />
#include &lt;iostream&gt;<br />
#include &lt;signal.h&gt;</p>
<p dir="auto">using namespace std;</p>
<p dir="auto">class MyClass {<br />
static MyClass* m;</p>
<p dir="auto">public:</p>
<p dir="auto">void handleSignal(int num){<br />
cout&lt;&lt;"Signal handled: "&lt;&lt;num&lt;&lt;endl;<br />
}</p>
<p dir="auto">static void setSignalHandlerObject(MyClass* mc) {<br />
m = mc;<br />
}</p>
<p dir="auto">static void callSignalHandler(int num){<br />
m-&gt;handleSignal(num);<br />
}<br />
};</p>
<p dir="auto">MyClass* MyClass::m = NULL;</p>
<p dir="auto">int main(){<br />
signal(SIGINT,MyClass::callSignalHandler);<br />
while(1);<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/88724</link><guid isPermaLink="true">https://forum.qt.io/post/88724</guid><dc:creator><![CDATA[situ117]]></dc:creator><pubDate>Wed, 18 May 2011 21:47:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 08:14:42 GMT]]></title><description><![CDATA[<p dir="auto">man sigaction</p>
<p dir="auto">--</p>
]]></description><link>https://forum.qt.io/post/88532</link><guid isPermaLink="true">https://forum.qt.io/post/88532</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 18 May 2011 08:14:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 08:07:38 GMT]]></title><description><![CDATA[<p dir="auto">@class MainWindow : public QMainWindow<br />
{<br />
Q_OBJECT<br />
private slots:<br />
void sigterm_handler(int);<br />
};</p>
<p dir="auto">MainWindow::MainWindow(QWidget <em>parent) :<br />
QMainWindow(parent),<br />
ui(new Ui::MainWindow)<br />
{<br />
ui-&gt;setupUi(this);<br />
struct sigaction action;<br />
fd  = open("/dev/hpi0",O_RDONLY);<br />
memset(&amp;action, 0, sizeof(action));<br />
action.sa_handler = sigterm_handler;<br />
action.sa_flags = 0;<br />
sigaction(SIGIO, &amp;action, NULL);<br />
fcntl(fd, F_SETOWN, getpid());<br />
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | FASYNC);<br />
}@<br />
error at "action.sa_handler = sigterm_handler;"<br />
message:     error: argument of type 'void (MainWindow::)(int)' does not match 'void (</em>)(int)'</p>
]]></description><link>https://forum.qt.io/post/88528</link><guid isPermaLink="true">https://forum.qt.io/post/88528</guid><dc:creator><![CDATA[yaoyulian]]></dc:creator><pubDate>Wed, 18 May 2011 08:07:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 08:07:16 GMT]]></title><description><![CDATA[<p dir="auto">Maybe this? (it does work for SIGSEGV and SIGINT, I often get those)<br />
@<br />
struct sigaction act, oact;<br />
memset((void*)&amp;act, 0, sizeof(struct sigaction));<br />
memset((void*)&amp;oact, 0, sizeof(struct sigaction));<br />
act.sa_flags = 0;<br />
act.sa_handler = &amp;signalHandler;<br />
sigaction(SIGINT, &amp;act, &amp;oact);<br />
sigaction(SIGKILL, &amp;act, &amp;oact);<br />
sigaction(SIGQUIT, &amp;act, &amp;oact);<br />
sigaction(SIGSTOP, &amp;act, &amp;oact);<br />
sigaction(SIGTERM, &amp;act, &amp;oact);@</p>
<p dir="auto">(...)</p>
<p dir="auto">@<br />
void signalHandler(int signal)<br />
{<br />
//print incoming signal<br />
switch(signal){<br />
case SIGINT: fprintf(stderr, "SIGINT =&gt; "); break;<br />
case SIGKILL: fprintf(stderr, "SIGKILL =&gt; "); break;<br />
case SIGQUIT: fprintf(stderr, "SIGQUIT =&gt; "); break;<br />
case SIGSTOP: fprintf(stderr, "SIGSTOP =&gt; "); break;<br />
case SIGTERM: fprintf(stderr, "SIGTERM =&gt; "); break;<br />
case SIGSEGV: fprintf(stderr, "SIGSEGV =&gt; "); break;<br />
default: fprintf(stderr, "APPLICATION EXITING =&gt; "); break;<br />
}</p>
<pre><code>//...
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">Hope it helps!!</p>
<p dir="auto">--</p>
]]></description><link>https://forum.qt.io/post/88527</link><guid isPermaLink="true">https://forum.qt.io/post/88527</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 18 May 2011 08:07:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to use &quot;sigaction&quot; in Qt? on Wed, 18 May 2011 07:58:37 GMT]]></title><description><![CDATA[<p dir="auto">I guess, it's not qt sphere.</p>
]]></description><link>https://forum.qt.io/post/88523</link><guid isPermaLink="true">https://forum.qt.io/post/88523</guid><dc:creator><![CDATA[alexander]]></dc:creator><pubDate>Wed, 18 May 2011 07:58:37 GMT</pubDate></item></channel></rss>