(C++) GetQtCreatorVersion

August 30, 2019 · View on GitHub

GetQtCreatorVersion is a version code snippet to obtain the version of Qt Creator.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Boost Boost: version 1.48
  • STL STL: GNU ISO C++ Library, version 4.7.2

 

 

 

 

 

Qt project file: CppGetQtCreatorVersion.pro

 


TEMPLATE = app LIBS += -lboost_filesystem -lboost_system CONFIG += console CONFIG -= qt SOURCES += main.cpp

 

 

 

 

 

main.cpp

 


#include <fstream> #include <string> #include <cstdlib> #include <vector> #include <boost/filesystem.hpp> ///FileToVector reads a file and converts it to a std::vector<std::string> ///From http://www.richelbilderbeek.nl/CppFileToVector.htm const std::vector<std::string> FileToVector(const std::string& filename) {   assert(boost::filesystem::exists(filename));   std::vector<std::string> v;   std::ifstream in(filename.c_str());   std::string s;   for (int i=0; !in.eof(); ++i)   {     std::getline(in,s);     v.push_back(s);   }   return v; } ///GetQtCreatorVersion obtains the version of Qt Creator ///From http://www.richelbilderbeek.nl/CppGetQtCreatorVersion.htm const std::string GetQtCreatorVersion() {   //'2>' denotes -AFAIK- 'Write to file only, no screen output'   std::system("qtcreator -version 2> tmp.txt");   const std::vector<std::string> v = FileToVector("tmp.txt");   const std::size_t sz = v.size();   assert(sz > 1);   for (std::size_t i=0; i!=sz; ++i)   {     const std::string& s = v[i];     if (s.substr(0,11) == std::string("Qt Creator "))     {       return s.substr(11,5);     }   }   return ""; } int main() {   std::cout << GetQtCreatorVersion() << '\n'; } /* Screen output: 2.5.2 */