Differentiate a program with a HASH in QT

0

Hi, I want to create an alias for each program that I create in qt and that this alias is different. I was thinking about using hashes and converting them into a string. For example: I compile a program every 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?

    
asked by Perl 17.10.2016 в 14:44
source

2 answers

0
  

I compile a program every 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__ and __TIME__ , this way every time you will have a different value unless you travel to the past or change the date of your system:

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

The previous code could print the following message:

El alias del programa es: Mi programa Oct 26 1985 22:29:34
    
answered by 17.10.2016 / 15:26
source
0

Yes, of course. You open the file in binary mode and you dump all the content in a chain. For example, through a std::ostringstream . Imagine a program that hasheaved 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;
}
    
answered by 17.10.2016 в 15:23