0 votes

Differentiating a program with a HASH in QT

Hello I want to create an alias to each program that I create in qt and that this alias is different. I was thinking of using hashes and converting it to a string. For example: I compile a program each time I compile that program it has to have a different ALIAS that does not match the next compilation.

Is it possible to do this?

0voto

Peregring-lk Points 2272

Of course you can. You open the file in binary mode and dump all the contents into a string. For example, through a std::ostringstream . Imagine a program that hashes itself:

#include <iostream>
#include <sstream>
#include <fstream>

int main(int argc, char* argv[])
{
    std::ifstream input(argv[0], std::ios::binary);
    std::ostringstream output;

    output << input.rdbuf();

    std::cout << tu_funcion_de_hasheo(output.str()) << std::endl;
}

0voto

PaperBirdMaster Points 24910

I compile a program each time I compile that program it has to have a different ALIAS that does not match the next compilation.

You could use the predefined macros of __DATE__ y __TIME__ This way you will have a different value each time unless you travel back in time or change the date of your system:

constexpr std::string ALIAS("Mi programa " __DATE__ " " __TIME__);
std::cout << "El alias del programa es: " << ALIAS;

The above code could print the following message:

El alias del programa es: Mi programa Oct 26 1985 22:29:34

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X