src/spacenav-demo-qt.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Mar 2019 16:20:51 +0100
branchv_0
changeset 6 49560660d230
parent 4 1383ad1c4f57
child 9 d3716f03efcd
permissions -rw-r--r--
emit MotionEvent and ButtonEvent + display button status
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
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
0
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>
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
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
    23
#include "SpacenavReceiver.h"
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    24
#include "SpacenavWindow.h"
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
    25
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
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
    27
	setlocale(LC_ALL, "");
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	QApplication app(argc, argv);
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
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
    30
	SpacenavReceiver t;
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    31
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    32
	SpacenavWindow w;
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    33
	w.show();
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    34
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    35
	QObject::connect(&t, &SpacenavReceiver::spacenavMotionEvent, &w, &SpacenavWindow::spacenavMotionEvent, Qt::ConnectionType::QueuedConnection);
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    36
	QObject::connect(&t, &SpacenavReceiver::spacenavButtonEvent, &w, &SpacenavWindow::spacenavButtonEvent, Qt::ConnectionType::QueuedConnection);
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
    37
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    38
	t.start();
2
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    39
	int qtResultCode = app.exec();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    40
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    41
	if (t.isRunning()) {
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    42
		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
    43
		t.terminate();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    44
		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
    45
		t.wait();
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    46
		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
    47
	}
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
21b0b2b0547e both buttons pressed → stop receiving events
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    49
	return qtResultCode;
0
37aa134ae57b empty QT project linked to spnav library
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
}