-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathcommonhelper.cpp
More file actions
49 lines (42 loc) · 1.13 KB
/
commonhelper.cpp
File metadata and controls
49 lines (42 loc) · 1.13 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
#include "commonhelper.h"
#include <QHostAddress>
#include <QNetworkInterface>
CommonHelper::CommonHelper(QObject *parent) :
QObject(parent)
{
}
QHostAddress CommonHelper::getLocalHostIP()
{
QList<QHostAddress> AddressList = QNetworkInterface::allAddresses();
QHostAddress result;
foreach(QHostAddress address, AddressList){
if(address.protocol() == QAbstractSocket::IPv4Protocol &&
address != QHostAddress::Null &&
address != QHostAddress::LocalHost){
if (address.toString().contains("127.0.")){
continue;
}
result = address;
break;
}
}
return result;
}
/**
* @brief getDateFromMacro
* @param time __DATE__
* @return
*/
static time_t getDateFromMacro(char const *time) {
char s_month[5];
int month, day, year;
struct tm t = {0};
static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
sscanf(time, "%s %d %d", s_month, &day, &year);
month = (strstr(month_names, s_month)-month_names)/3;
t.tm_mon = month;
t.tm_mday = day;
t.tm_year = year - 1900;
t.tm_isdst = -1;
return mktime(&t);
}