index.html 16.1 KB
Newer Older
1 2 3 4 5 6
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

Morten Sorvig's avatar
Morten Sorvig committed
7
		<title>Qt for Wasm</title>
8 9 10 11 12 13

		<link rel="stylesheet" href="reveal.js/css/reveal.css">
		<link rel="stylesheet" href="reveal.js/css/theme/white.css">

		<!-- Theme used for syntax highlighting of code -->
		<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
Morten Sorvig's avatar
Morten Sorvig committed
14 15 16 17 18 19 20 21 22 23 24 25 26
        
        <!-- Left-justify content Hack -->
        <style type="text/css">
          .reveal p {
            text-align: left;
          }
          .reveal ul {
            display: block;
          }
          .reveal ol {
            display: block;
          }
        </style>
27 28 29 30 31 32 33 34 35 36 37 38 39 40

		<!-- Printing and PDF exports -->
		<script>
			var link = document.createElement( 'link' );
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
			document.getElementsByTagName( 'head' )[0].appendChild( link );
		</script>
	</head>
	<body>
		<div class="reveal">
			<div class="slides">
				<section>
Morten Sorvig's avatar
Morten Sorvig committed
41 42
                    <img width=150 height=75 src="images/qtlogo.svg">
                    <h2>Qt for WebAssembly</h2>
Morten Sorvig's avatar
Morten Sorvig committed
43 44
                    <img width=300 height=300 src="images/qtws19.png">
                    <p>morten.sorvig@qt.io<p/>
45
                </section>
Morten Sorvig's avatar
Morten Sorvig committed
46
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
47 48
                    <h2>Demo: Qt Design Studio Viewer</h2>
                    <a href="https://qt-webassembly.io/designviewer/" target="_blank">https://qt-webassembly.io/designviewer/</a>
Morten Sorvig's avatar
Morten Sorvig committed
49 50 51
                </section>
                <section>
                    <h2>Agenda</h2>
Morten Sorvig's avatar
Morten Sorvig committed
52 53 54 55 56 57 58 59 60 61 62 63
                    <p>Motivation</p>
                    <p>Getting Started</p>
                    <p>Development Topics</p>
                        <ul>
                          <li>local file access</li>
                          <li>networking</li>
                          <li>multithreading</li>
                          <li>drawing to multiple canvases</li>
                        </ul>
                    <p>Work-in-Progress Topics</p>
                    <br>
                    <p>Presentation Source: git.qt.io/mosorvig/qtws19-wasm</p>
Morten Sorvig's avatar
Morten Sorvig committed
64 65
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
66
                    <h2>Web Applications</h2>
Morten Sorvig's avatar
Morten Sorvig committed
67 68
                    <p>Build once, deploy everywhere</p>
                    <p>Security through sandboxing</p>
Morten Sorvig's avatar
Morten Sorvig committed
69 70
                    <p>No installation required</p>
                    <p>Publish instantly; no app-store review</p>
Morten Sorvig's avatar
Morten Sorvig committed
71 72
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
73
                    <h2>Warning: Work In Progress!</h2>
Morten Sorvig's avatar
Morten Sorvig committed
74 75
                    <p>No system font support (bring your own fonts)</p>
                    <p>No accessibility/screen reader support</p>
Morten Sorvig's avatar
Morten Sorvig committed
76
                    <p>No support for re-entering the event loop - e.g. with QDialog::exec()</p>
Morten Sorvig's avatar
Morten Sorvig committed
77 78
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
79 80 81 82 83 84
                    <h2>Getting Started</h2>
                    <p>Install Emscripten, build "Hello World"</p>
                    <p>Build Qt from source</p>
                    <p>Build Qt for WebAssembly</p>
                    <p>Enable Qt Creator WebAssembly Plugin (4.11)</p>
                </section>    
Morten Sorvig's avatar
Morten Sorvig committed
85
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
86
                    <h2>Emscripten: <b>emsdk</b></h2>
Morten Sorvig's avatar
Morten Sorvig committed
87 88 89
                    <table>
				    <thead>
						<tr>
Morten Sorvig's avatar
Morten Sorvig committed
90 91
							<th>Action</th>
							<th>Description</th>
Morten Sorvig's avatar
Morten Sorvig committed
92 93 94
						</tr>
					</thead>
					<tbody>
Morten Sorvig's avatar
Morten Sorvig committed
95 96 97 98 99 100 101
						<tr>
							<td>List</td>
                            <td>./emsdk list --old</td>
						</tr>
						<tr>
							<td>Install</td>
							<td>./emsdk install sdk-1.38.27-64bit</td>
Morten Sorvig's avatar
Morten Sorvig committed
102 103
						</tr>
						<tr>
Morten Sorvig's avatar
Morten Sorvig committed
104 105
							<td>Activate</td>
                            <td>./emsdk activate --embedded sdk-1.38.27-64bit</td>
Morten Sorvig's avatar
Morten Sorvig committed
106 107
						</tr>
						<tr>
Morten Sorvig's avatar
Morten Sorvig committed
108 109
							<td>Environment</td>
                            <td>source ./emsdk_env.sh</td>
Morten Sorvig's avatar
Morten Sorvig committed
110 111
						</tr>
						<tr>
Morten Sorvig's avatar
Morten Sorvig committed
112 113
							<td>Build</td>
                            <td>em++ hello.cpp -o hello.html</td>
Morten Sorvig's avatar
Morten Sorvig committed
114 115 116 117 118
						</tr>
					</tbody>
				    </table>
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
119 120 121
                    <h2>Emscripten: hello.html</h2>
                    <iframe width="600" height="600" src = "hello/hello.html"></iframe>    
                </section>
Morten Sorvig's avatar
Morten Sorvig committed
122
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
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
                    <table>
                    <h2>Qt from git</h2>
				    <thead>
						<tr>
							<th>Action</th>
							<th>Description</th>
						</tr>
					</thead>
					<tr>
						<td>Clone</td>
                        <td>git clone https://code.qt.io/qt/qt5.git</td>
					</tr>
					<tr>
						<td>Get Modules</td>
                        <td>./init-repository --module-subset= "qtbase, qtdeclarative, -qtwebengine"</td>
					</tr>
					<tr>
						<td>Configure</td>
                        <td>./configure -release -no-thread -static -nomake examples -xplatform wasm-emscripten</td>
					</tr>
					<tr>
						<td>Build</td>
                        <td>make module-qtbase module-qtdeclarative</td>
					</tr>
                </table>
Morten Sorvig's avatar
Morten Sorvig committed
148 149
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
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
                                    <h2>Application Build Output</h2>
                                    <table>
                				    <thead>
                						<tr>
                							<th>Name</th>
                							<th>Source</th>
                                            <th>Purpose</th>
                						</tr>
                					</thead>
                					<tbody>
                						<tr style>
                							<td>app.html</td>
                							<td>Qt</td>
                							<td>HTML container</td>
                						</tr>
                						<tr>
                							<td>qtloader.js</td>
                							<td>Qt</td>
                                            <td>JS API for loading Qt apps</td>
                						</tr>
                						<tr>
                							<td>app.js</td>
                                            <td>emscripten</td>
                							<td>app JavaScript runtime</td>
                						</tr>
                						<tr>
                							<td>app.wasm</td>
                                            <td>emscripten</td>
                							<td>app binary</td>
                						</tr>
                					</tbody>
                				    </table>
Morten Sorvig's avatar
Morten Sorvig committed
182 183
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
                                    <h2>Wasm Binary Sizes</h2>
                    				<table>
                    				    <thead>
                    						<tr>
                    							<th>Modules</th>
                    							<th>gzip</th>
                                                <th>brotli</th>
                    						</tr>
                    					</thead>
                    					<tbody>
                    						<tr>
                    							<td>Core Gui</td>
                    							<td>2.8MB</td>
                                                <td>2.1MB</td>
                    						</tr>
                    						<tr>
                    							<td>Core Gui Widgets</td>
                    							<td>4.3MB</td>
                                                <td>3.2MB</td>
                    						</tr>
                    						<tr>
                    							<td>Core Gui Widgets Quick Charts</td>
                    							<td>8.6MB</td>
                    							<td>6.3MB</td>
                    						</tr>
                    					</tbody>
                                        <p>Typical compression ratios: 3:1 - 5:1</p>
                                    </table>
                </section>
                
                <section>
                        <h2>Development Web Server</h2>
                        <p>Purpose: serve files from localhost and/or local ip, provide 
                            <i><a href= "https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts" target="_blank">secure context</a></i>, set headers</p>
                        <table>
        				<thead>
        				    <tr>
        						<th>Protocol</th>
        						<th> </th>
        					</tr>
        				</thead>
        				<tr>
        					<td>file://</td>
                            <td><i>does not work</i></td>
        				</tr>
        				<tr>
        					<td>http://localhost/</td>
                            <td>python3 -m http.server</td>
        				</tr>
        				<tr>
        					<td>https://</td>
                            <td><i>use custom server<i/></td>
        				</tr>
                        </table>
                </section>
                <section>
                        <h2>pyserver</h2>
                        <p>https server in ~40 lines of python (<a href=https://bugreports.qt.io/browse/QTBUG-79087 target="_blank">QTBUG-79087</a>)</p>
                        <p>Generates certifactes using <a href=https://github.com/FiloSottile/mkcert target="_blank">mkcert</a></p>
                        <p>Serves from localhost and local ip</p>
                        <p>Sets headers required for multi-threading</p>
Morten Sorvig's avatar
Morten Sorvig committed
245 246 247
                </section>
                <section>
                    <h2>Local File Access</h2>
Morten Sorvig's avatar
Morten Sorvig committed
248 249 250
                        <p>The web sandbox prevents direct file system access</p>
                        <p>The web platform has API for opening a file dialog, and starting a file download</p>
                        <p>Qt has new QFileDialog API which covers this use case</p>
Morten Sorvig's avatar
Morten Sorvig committed
251 252 253
                </section>
                <section>
                    <h2>Local File Access</h2>
Morten Sorvig's avatar
Morten Sorvig committed
254
                    <p>Callback-based getOpenFileContent()</p>
Morten Sorvig's avatar
Morten Sorvig committed
255
					<pre><code class="hljs" data-trim contenteditable>
Morten Sorvig's avatar
Morten Sorvig committed
256 257 258
QFileDialog::getOpenFileContent("*.txt",
    [](const QString &fileName,
       const QByteArray &fileContent) {
Morten Sorvig's avatar
Morten Sorvig committed
259 260 261 262 263 264 265 266 267

       qDebug() << "Got" << fileContent.count()
                << "bytes from" << fileName;
});
</code></pre>                    
                    <p>Fire-and-forget saveFile()</p>
                    <pre><code class="hljs" data-trim contenteditable>
QByteArray content = ...;
QString fileNameHint = ...;
Morten Sorvig's avatar
Morten Sorvig committed
268
QFileDialog::saveFileContent(content, fileNameHint);
Morten Sorvig's avatar
Morten Sorvig committed
269 270 271
                    </code></pre>                    
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
272
                    <iframe width="900" height="600" src="qt/slate/app/slate.html"></iframe>
Morten Sorvig's avatar
Morten Sorvig committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286
                </section>
                <section>
                    <h2>Networking</h2>
    				<table>
    				    <thead>
    						<tr>
    							<th>API</th>
    							<th>Protocol</th>
                                <th>Notes</th>
    						</tr>
    					</thead>
    					<tbody>
    						<tr>
    							<td>QNetworkAccessManager</td>
Morten Sorvig's avatar
Morten Sorvig committed
287
    							<td>Http(s)</td>
Morten Sorvig's avatar
Morten Sorvig committed
288
                                <td>Same Origin / CORS host</td>
Morten Sorvig's avatar
Morten Sorvig committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    						</tr>
    						<tr>
    							<td>QWebSocket</td>
    							<td>WebSocket</td>
                                <td>Any host</td>
    						</tr>
    						<tr>
    							<td>QAbstractSocket</td>
    							<td>WebSocket</td>
                                <td>Websockify forwarding host</td>
    						</tr>
    					</tbody>
    				    </table>
                    </section>
                </section>
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
                    <h2>Multithreading</h2>
                    <p><a href="qt/widgets_mandelbrot/widgets_mandelbrot.html" target ="_blank">mandelbrot demo</a><p>
                    <p><a href="https://git.qt.io/mosorvig/qt-webassembly-examples/tree/5.13/mandelbrot"> mandelbrot source </a><p>
                </section>
                <section>
                    <h2>Enabling Multithreading</h2>
                    <p>Configure Qt with -feature-thread<p>
                    <p>Configure App<p>
                        <ul>
                          <li>QMAKE_WASM_TOTAL_MEMORY</li>
                          <li>QMAKE_WASM_PTHREAD_POOL_SIZE</li>
                        </ul>
                        
                    <p>Enable threading in browser<p>
                        <ul>
                          <li>javascript.options.shared_memory (Firefox)</li>
                          <li>Headers: Cross-Origin-Opener-Policy, Cross-Origin-Embedder-Policy</li>
                        </ul>
                </section>
                <section>
                    <h2>Multithreading Tips</h2>
                    <p>Read Emscripten's <a href="https://emscripten.org/docs/porting/pthreads.html?highlight=threading" target = "_blank"> Pthreads Support </a> documentation <p>
                    <p>Don't block the main thread!<p>
                    <p>That includes when calling pthread_join()<p>
Morten Sorvig's avatar
Morten Sorvig committed
329 330 331
                </section>

                <section>
Morten Sorvig's avatar
Morten Sorvig committed
332 333 334 335 336
                    <h2>Rendering to Multiple Canvases</h2>
                    <p>Draw to multiple canvases from a single wasm instance<p>
                    <p>Each canvas maps to a QScreen<p>
                    <p><a href="qt/gui_multicanvas/multicanvas.html" target ="_blank">multicanvas demo</a><p>
                    <p><a href="https://git.qt.io/mosorvig/qt-webassembly-examples/tree/5.13/multicanvas" target = "_blank"> multicanvas source</a><p>
Morten Sorvig's avatar
Morten Sorvig committed
337
                </section>
Morten Sorvig's avatar
Morten Sorvig committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

                <section>
                    <h2>Rendering to Multiple Canvases</h2>
                    <p>Add canvas from JavaScript code</p>
					<pre><code class="hljs" data-trim contenteditable>
let canvas = ...
qtloader.addCanvasElement(canvas);
</code></pre>                    
                    <p>Handle screenAdded signal</p>
					<pre><code class="hljs" data-trim contenteditable>
QObject::connect(qApp, &QGuiApplication::screenAdded, 
                 [=](QScreen *screen) {
    QWindow *window = new AppWindow();
    window->setScreen(screen);
    window->showFullScreen();
});
</code></pre>                    
Morten Sorvig's avatar
Morten Sorvig committed
355
                </section>
Morten Sorvig's avatar
Morten Sorvig committed
356

Morten Sorvig's avatar
Morten Sorvig committed
357
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371
                    <h2>The Qt Quick Web Runtime</h2>
                    <p>Binary distribution of Qt Quick</p>
                    <p>Install with e.g. "git clone" or "npm install"</p>
                    <p>JavaScript API:</p>
					<pre><code class="hljs" data-trim contenteditable>
let containerElement = ...
let qmlSourceCode = ...
let qtQuick = new QtQuickRuntime({
    container: containerElement
});
qtQuick.setQmlSourceCode(qmlSourceCode)
qtQuick.load()
</code></pre> 
                <p>Watch <a href="https://bugreports.qt.io/browse/QTBUG-74293" target="_blank">QTBUG-74293</a> for updates</p>
Morten Sorvig's avatar
Morten Sorvig committed
372 373 374
                </section>
                
                <section>
Morten Sorvig's avatar
Morten Sorvig committed
375 376 377 378 379 380 381 382 383
                <h2>Qml Live Editor</h2>
                <iframe width="600" height="600" src = "qt/quick_runtime/index.html"></iframe>    
                </section>

                <section>
                    <h2>Accessibility Prototype</h2>
                    <p>Work-in-progress support for screen readers</p>
                    <p></p>
                    <p><a href="qt/accessibility/accessibleqt.html" target ="_blank">accessibility demo</a><p>
Morten Sorvig's avatar
Morten Sorvig committed
384 385 386 387 388
                </section>

                <section>
                <img width=150 height=75 src="images/qtlogo.svg">
                <h1>Thanks!</h1>
Morten Sorvig's avatar
Morten Sorvig committed
389 390 391
                <p><a href="https://doc.qt.io/qt-5/wasm.html" target ="_blank">doc.qt.io/qt-5/wasm.html</a></p>
                <p><a href="https://wiki.qt.io/Qt_for_WebAssembly" target ="_blank">wiki.qt.io/Qt_for_WebAssembly</a></p>
                <p><a href="https://git.qt.io/mosorvig/qtws19-wasm" target ="_blank">git.qt.io/mosorvig/qtws19-wasm</a></p>
Morten Sorvig's avatar
Morten Sorvig committed
392
                </section>
393 394 395 396 397 398 399 400 401 402 403
			</div>
		</div>

		<script src="reveal.js/lib/js/head.min.js"></script>
		<script src="reveal.js/js/reveal.js"></script>

		<script>
			// More info about config & dependencies:
			// - https://github.com/hakimel/reveal.js#configuration
			// - https://github.com/hakimel/reveal.js#dependencies
			Reveal.initialize({
Morten Sorvig's avatar
Morten Sorvig committed
404 405 406
                history: true,
                slideNumber: true,
                viewDistance: 3,
407 408 409 410 411 412 413 414 415 416
				dependencies: [
					{ src: 'reveal.js/plugin/markdown/marked.js' },
					{ src: 'reveal.js/plugin/markdown/markdown.js' },
					{ src: 'reveal.js/plugin/notes/notes.js', async: true },
					{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
				]
			});
		</script>
	</body>
</html>