Looks like QtPurchasing uses deprecated AIDL billing library and people say that it crashes on some devices. See https://developer.android.com/google/play/billing/deprecation-faq for more information. Probably they are going to update it in 5.15.7 and move it into examples in QT 6, so it is not clear exactly what will happen with it, we probably better wait QT 5.15.7 to be released.
(more…)Adding a header to source files
Put the header content into a text file and load it into a variable:
cd ~/temp/
nano h.txt
h=$(<h.txt)
Enabling colors in Window 10 console
Add DWORD
key VirtualTerminalLevel=1
to HKEY_CURRENT_USER\Console
:
Did you already learn what are C++ concepts?
In C++20 we can do this:
#include <ranges>
#include <vector>
template <std::ranges::range Range>
requires std::same_as<std::ranges::range_value_t<Range>, int>
auto TransformIt(Range r)
{
return r | std::views::transform([](int n) { return n * n; });
}
int main()
{
std::vector<int> v;
auto r = TransformIt(v);
return 0;
}
std::unique_ptr with a deleter that throws an exception
The program below is terminated when the deleter throws the exception:
#include <iostream>
#include <memory>
struct X
{
int value;
};
struct Deleter
{
void operator()(X* p) noexcept(false)
{
if (p->value == 0)
{
throw std::logic_error("Can't delete a zero.");
}
delete p;
}
};
Invokable constructor in QT
In QT 5.15 I declare a class with an invokable constructor:
class TestClass : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE TestClass(QString val) {}
};
Q_DECLARE_METATYPE(TestClass*)
register its type:
qRegisterMetaType<TestClass*>();
An example of heterogeneous lookup with std::unordered_set in C++20
std::unordered_set
has a template find
function in C++20. To make it work I define a custom hash and a custom equality compares as follows:
struct BotSettings
{
std::string type;
std::string name;
bool started;
};
How my trading bot buys the cryptocurrency
I used a simple algorithm a got an interesting effect: the bot often buys at the peaks of the falling price. Below I provided some examples of buying the cryptocurrency on Binance crypto exchange:
DASH/USDT:
(more…)‘Invalid UTF-8 code encountered.’ close reason with QWebSocket
I get close reason: ‘Invalid UTF-8 code encountered.’ (code=1007) with QWebSocket
in the following scenario:
- I connect to
Binance
streamwss://stream.binance.com:9443/stream
withQWebSocket::open
. - Successfully receive messages for some time period (a few hours).
Binance
disconnects me when its servers load increases (because I have low-priority API) and I get close reason code=1000 that indicates a normal closure.- Try to reconnect multiple times by calling
QWebSocket::open
again, butBinance
closes the connection with close reason ‘Invalid UTF-8 code encountered.’ (code=1007) that indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message). - Restart the application manually and connect successfully.
The difficulty of reproducing the bug is that Binance
disconnects me rarely (once a day, for example) and experimentation with disconnecting the network cable from my machine does not have this effect, after I connect the cable back, QWebSocker
reconnects successfully. When I disconnect the network cable I get Error: ‘Unknown error’ (code=-1), Close reason: ” (code=1000).
My first trade with my simple Binance bot
It calculates the difference between 2.5 hour moving average (MA) and the current price, when the difference exceeds the threshold it buys:
(more…)