Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) GetQtCreatorVersion

 

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:

 

 

 

 

 

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
*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml