-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.cpp
59 lines (44 loc) · 1.63 KB
/
controller.cpp
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
#include "controller.h"
#include <QQmlComponent>
#include <QQuickItem>
#include <QQmlProperty>
#include <iostream>
#ifdef WIN32
static const std::string libExtension = ".dll";
#endif
#ifdef __linux__
static const std::string libExtension = ".so";
#endif
Controller::Controller(QObject *parent)
: QObject{parent}
{}
void Controller::showLibraryQml(int index)
{
QQmlEngine *engine = qmlEngine(this);
QQmlComponent component(engine);
std::string libName;
if(index == 0) {
libName = "libMultiplyLib";
dll_loader = std::make_unique<LibLoader<ExampleApi>>(libName + std::string(libExtension));
dll_loader->openLib();
lib_object = dll_loader->getInstance();
component.setData(lib_object->getQML(), QUrl());
QQuickItem *item = qobject_cast<QQuickItem*>(component.createWithInitialProperties(QVariantMap{{lib_object->propertyName().c_str(), QVariant::fromValue(lib_object.get())}}));
emit qmlLoaded(item);
} else {
libName = "libDivideLib";
dll_loader2 = std::make_unique<LibLoader<ExampleApi>>(libName + std::string(libExtension));
dll_loader2->openLib();
lib_object2 = dll_loader2->getInstance();
component.setData(lib_object2->getQML(), QUrl());
QQuickItem *item = qobject_cast<QQuickItem*>(component.createWithInitialProperties(QVariantMap{{lib_object2->propertyName().c_str(), QVariant::fromValue(lib_object2.get())}}));
emit qmlLoaded(item);
}
}
void Controller::clickUpdate(int num)
{
if(lib_object)
lib_object->performComputation(num);
if(lib_object2)
lib_object2->performComputation(num);
}