(C++) GetQtCreatorVersion
August 30, 2019 · View on GitHub
GetQtCreatorVersion is a version code snippet to obtain the version of Qt Creator.
Technical facts
Operating system(s) or programming environment(s)
Qt Creator 2.5.2
- G++ 4.7.2
Libraries used:
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 */