-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreManager.cpp
More file actions
56 lines (47 loc) · 1.56 KB
/
Copy pathCoreManager.cpp
File metadata and controls
56 lines (47 loc) · 1.56 KB
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
#include "CoreManager.h"
CoreManager::CoreManager(QObject *parent)
:QObject(parent)
{
}
void CoreManager::onDecimalChangedSlot(const QString &text)
{
bool ok;
long long valueDec = text.toLongLong(&ok); // Convert text to decimal
if (!ok) {
qInfo("Error converting text to decimal");
emit processFailed();
return;
}
QString valueBin = QString::number(valueDec, 2); // Convert decimal to binary
QString valueHex = QString::number(valueDec, 16); // Convert decimal to hexadecimal
emit decimalProcessed(valueBin, valueHex.toUpper());
}
void CoreManager::onHexChangedSlot(const QString &text)
{
bool ok;
unsigned long long decimal = text.toULongLong(&ok, 16); // Convert hexadecimal string to decimal
if (!ok) {
qInfo("Error converting hexadecimal input");
emit processFailed();
return;
}
QString binary = QString::number(decimal, 2); // Convert decimal to binary
emit hexProcessed(QString::number(decimal), binary);
}
void CoreManager::onBinaryChangedSlot(const QString &text)
{
bool ok;
unsigned long long num = text.toULongLong(&ok, 16); // Convert from hexadecimal to unsigned integer
if (!ok) {
qInfo("Error converting hexadecimal input");
emit processFailed();
return;
}
long long decimal = text.toLongLong(&ok, 2); // Convert from binary to decimal
if (!ok) {
qInfo("Error converting binary input");
emit processFailed();
return;
}
emit binaryProcessed(QString::number(decimal), QString::number(num, 2));
}