src/spacenav-demo-qt.cpp
author František Kučera <franta-hg@frantovo.cz>
Wed, 06 Mar 2019 21:08:34 +0100
branchv_0
changeset 2 21b0b2b0547e
parent 1 2a3e9f07c128
child 4 1383ad1c4f57
permissions -rw-r--r--
both buttons pressed → stop receiving events
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Spacenav Demo Qt
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <stdio.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <QApplication>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <QThread>
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    22
#include <QMainWindow>
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <stdlib.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <signal.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <X11/Xlib.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <spnav.h>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    29
#include "SpacenavReceiver.h"
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    30
//#include "SpacenavWindow.h"
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    31
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
int main(int argc, char**argv) {
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	setlocale(LC_ALL, "");
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	QApplication app(argc, argv);
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    36
	SpacenavReceiver t;
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    37
	t.start();
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    38
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    39
	// QMainWindow w;
1
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    40
	// w.show();
2a3e9f07c128 receive spacenav events (in separate thread) and print them on stderr
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    41
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    42
	int qtResultCode = app.exec();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    43
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    44
	if (t.isRunning()) {
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    45
		std::wcerr << L"Background RelationalReader thread is still running → terminate()" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    46
		t.terminate();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    47
		std::wcerr << L"Background RelationalReader thread was terminated → wait()" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
		t.wait();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    49
		std::wcerr << L"Background RelationalReader thread wait() finished" << std::endl;
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    50
	}
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    51
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    52
	return qtResultCode;
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
}