aboutsummaryrefslogtreecommitdiff
path: root/index.html
blob: 27f030e0b2fae458daabf9b8a9394f045b13850b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- BEGIN opengraph metadata -->
<meta property="og:title" content="Doxygen Awesome" />
<meta property="og:image" content="https://repository-images.githubusercontent.com/348492097/4f16df80-88fb-11eb-9d31-4015ff22c452" />
<meta property="og:description" content="Custom CSS theme for doxygen html-documentation with lots of customization parameters." />
<meta property="og:url" content="https://jothepro.github.io/doxygen-awesome-css/" />
<!-- END opengraph metadata -->
<!-- BEGIN twitter metadata -->
<meta name="twitter:image:src" content="https://repository-images.githubusercontent.com/348492097/4f16df80-88fb-11eb-9d31-4015ff22c452" />
<meta name="twitter:title" content="Doxygen Awesome" />
<meta name="twitter:description" content="Custom CSS theme for doxygen html-documentation with lots of customization parameters." />
<!-- END twitter metadata -->
<title>SingleApplication: SingleApplication</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link rel="icon" type="image/svg+xml" href="logo.drawio.svg"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript" src="doxygen-awesome-fragment-copy-button.js"></script>
<script type="text/javascript" src="doxygen-awesome-paragraph-link.js"></script>
<script type="text/javascript" src="toggle-alternative-theme.js"></script>
<script type="text/javascript">
    DoxygenAwesomeFragmentCopyButton.init()
    DoxygenAwesomeDarkModeToggle.init()
    DoxygenAwesomeParagraphLink.init()
</script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- https://tholman.com/github-corners/ -->
<a href="https://github.com/itay-grudev/SingleApplication" class="github-corner" title="View source on GitHub" target="_blank">
    <svg viewBox="0 0 250 250" width="40" height="40" style="position: absolute; top: 0; border: 0; right: 0; z-index: 99;" aria-hidden="true">
    <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">SingleApplication
   </div>
   <div id="projectbrief">Replacement for QtSingleApplication</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('index.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title"><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a> </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="md_README"></a> <a href="https://github.com/itay-grudev/SingleApplication/actions"><img src="https://github.com/itay-grudev/SingleApplication/workflows/CI:%20Build%20Test/badge.svg" alt="CI" style="pointer-events: none;" class="inline"/></a></p>
<p>This is a replacement of the QtSingleApplication for <code>Qt5</code> and <code>Qt6</code>.</p>
<p>Keeps the Primary Instance of your Application and kills each subsequent instances. It can (if enabled) spawn secondary (non-related to the primary) instances and can send data to the primary instance from secondary instances.</p>
<h1><a class="anchor" id="autotoc_md43"></a>
Documentation</h1>
<p>You can find the full usage reference <a href="https://itay-grudev.github.io/SingleApplication/classSingleApplication.html">here</a>.</p>
<h1><a class="anchor" id="autotoc_md44"></a>
Usage</h1>
<p>The <code><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a></code> class inherits from whatever <code>Q[Core|Gui]Application</code> class you specify via the <code>QAPPLICATION_CLASS</code> macro (<code>QCoreApplication</code> is the default). Further usage is similar to the use of the <code>Q[Core|Gui]Application</code> classes.</p>
<p>You can use the library as if you use any other <code>QCoreApplication</code> derived class:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;QApplication&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;SingleApplication.h&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[] )</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classSingleApplication.html">SingleApplication</a> app( argc, argv );</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> app.exec();</div>
<div class="line">}</div>
<div class="ttc" id="aclassSingleApplication_html"><div class="ttname"><a href="classSingleApplication.html">SingleApplication</a></div><div class="ttdoc">Handles multiple instances of the same Application.</div><div class="ttdef"><b>Definition:</b> singleapplication.h:43</div></div>
</div><!-- fragment --><p>To include the library files I would recommend that you add it as a git submodule to your project. Here is how:</p>
<div class="fragment"><div class="line">git submodule add https://github.com/itay-grudev/SingleApplication.git singleapplication</div>
</div><!-- fragment --><p><b>Qmake:</b></p>
<p>Then include the <code>singleapplication.pri</code> file in your <code>.pro</code> project file.</p>
<div class="fragment"><div class="line">include(singleapplication/singleapplication.pri)</div>
<div class="line">DEFINES += QAPPLICATION_CLASS=QApplication</div>
</div><!-- fragment --><p><b>CMake:</b></p>
<p>Then include the subdirectory in your <code>CMakeLists.txt</code> project file.</p>
<div class="fragment"><div class="line">set(QAPPLICATION_CLASS QApplication CACHE STRING &quot;Inheritance class for SingleApplication&quot;)</div>
<div class="line">add_subdirectory(src/third-party/singleapplication)</div>
<div class="line">target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication)</div>
</div><!-- fragment --><p>The library sets up a <code>QLocalServer</code> and a <code>QSharedMemory</code> block. The first instance of your Application is your Primary Instance. It would check if the shared memory block exists and if not it will start a <code>QLocalServer</code> and listen for connections. Each subsequent instance of your application would check if the shared memory block exists and if it does, it will connect to the QLocalServer to notify the primary instance that a new instance had been started, after which it would terminate with status code <code>0</code>. In the Primary Instance <code><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a></code> would emit the <code>instanceStarted()</code> signal upon detecting that a new instance had been started.</p>
<p>The library uses <code>stdlib</code> to terminate the program with the <code>exit()</code> function.</p>
<p>Also don't forget to specify which <code>QCoreApplication</code> class your app is using if it is not <code>QCoreApplication</code> as in examples above.</p>
<h1><a class="anchor" id="autotoc_md45"></a>
Instance started signal</h1>
<p>The <code><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a></code> class implements a <code>instanceStarted()</code> signal. You can bind to that signal to raise your application's window when a new instance had been started, for example.</p>
<div class="fragment"><div class="line"><span class="comment">// window is a QWindow instance</span></div>
<div class="line">QObject::connect(</div>
<div class="line">    &amp;app,</div>
<div class="line">    &amp;<a class="code" href="classSingleApplication.html#a1aaf2ba6e56fc03638d283d7a39584b1">SingleApplication::instanceStarted</a>,</div>
<div class="line">    &amp;window,</div>
<div class="line">    &amp;QWindow::raise</div>
<div class="line">);</div>
<div class="ttc" id="aclassSingleApplication_html_a1aaf2ba6e56fc03638d283d7a39584b1"><div class="ttname"><a href="classSingleApplication.html#a1aaf2ba6e56fc03638d283d7a39584b1">SingleApplication::instanceStarted</a></div><div class="ttdeci">void instanceStarted()</div><div class="ttdoc">Triggered whenever a new instance had been started, except for secondary instances if the Mode::Secon...</div></div>
</div><!-- fragment --><p>Using <code>SingleApplication::instance()</code> is a neat way to get the <code><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a></code> instance for binding to it's signals anywhere in your program.</p>
<p><em>Note:</em> On Windows the ability to bring the application windows to the foreground is restricted. See <a class="el" href="md_Windows.html">Windows specific implementations</a> for a workaround and an example implementation.</p>
<h1><a class="anchor" id="autotoc_md46"></a>
Secondary Instances</h1>
<p>If you want to be able to launch additional Secondary Instances (not related to your Primary Instance) you have to enable that with the third parameter of the <code><a class="el" href="classSingleApplication.html" title="Handles multiple instances of the same Application.">SingleApplication</a></code> constructor. The default is <code>false</code> meaning no Secondary Instances. Here is an example of how you would start a Secondary Instance send a message with the command line arguments to the primary instance and then shut down.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classSingleApplication.html">SingleApplication</a> app( argc, argv, <span class="keyword">true</span> );</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">if</span>( app.isSecondary() ) {</div>
<div class="line">        app.sendMessage(  app.arguments().join(<span class="charliteral">&#39; &#39;</span>)).toUtf8() );</div>
<div class="line">        app.exit( 0 );</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> app.exec();</div>
<div class="line">}</div>
</div><!-- fragment --><p><em>Note:</em> A secondary instance won't cause the emission of the <code>instanceStarted()</code> signal by default. See <code><a class="el" href="classSingleApplication.html#af627160aff1baf822780f3232e43cc3f" title="Mode of operation of SingleApplication. Whether the block should be user-wide or system-wide and whet...">SingleApplication::Mode</a></code> for more details.*</p>
<p>You can check whether your instance is a primary or secondary with the following methods:</p>
<div class="fragment"><div class="line">app.isPrimary();</div>
<div class="line"><span class="comment">// or</span></div>
<div class="line">app.isSecondary();</div>
</div><!-- fragment --><p><em>Note:</em> If your Primary Instance is terminated a newly launched instance will replace the Primary one even if the Secondary flag has been set.*</p>
<h1><a class="anchor" id="autotoc_md47"></a>
Examples</h1>
<p>There are three examples provided in this repository:</p>
<ul>
<li>Basic example that prevents a secondary instance from starting <a href="https://github.com/itay-grudev/SingleApplication/tree/master/examples/basic"><code>examples/basic</code></a></li>
<li>An example of a graphical application raising it's parent window <a href="https://github.com/itay-grudev/SingleApplication/tree/master/examples/calculator"><code>examples/calculator</code></a></li>
<li>A console application sending the primary instance it's command line parameters <a href="https://github.com/itay-grudev/SingleApplication/tree/master/examples/sending_arguments"><code>examples/sending_arguments</code></a></li>
</ul>
<h1><a class="anchor" id="autotoc_md48"></a>
Versioning</h1>
<p>Each major version introduces either very significant changes or is not backwards compatible with the previous version. Minor versions only add additional features, bug fixes or performance improvements and are backwards compatible with the previous release. See <a class="el" href="md_CHANGELOG.html">CHANGELOG.md</a> for more details.</p>
<h1><a class="anchor" id="autotoc_md49"></a>
Implementation</h1>
<p>The library is implemented with a <code>QSharedMemory</code> block which is thread safe and guarantees a race condition will not occur. It also uses a <code>QLocalSocket</code> to notify the main process that a new instance had been spawned and thus invoke the <code>instanceStarted()</code> signal and for messaging the primary instance.</p>
<p>Additionally the library can recover from being forcefully killed on *nix systems and will reset the memory block given that there are no other instances running.</p>
<h1><a class="anchor" id="autotoc_md50"></a>
License</h1>
<p>This library and it's supporting documentation are released under <code>The MIT License (MIT)</code> with the exception of the Qt calculator examples which is distributed under the BSD license. </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>