Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) QtCreator_5_1

 

QtQt CreatorLubuntu

 

Qt Creator 5.1 example 1 is a Qt Creator 5.1 example.

 

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: ./CppQtCreator_5_1/CppQtCreator_5_1.pro

 

win32 {
  #Add the line below when cross-compiling
  #CONFIG += static
}

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app

SOURCES += main.cpp \
        qtdialog.cpp

HEADERS  += qtdialog.h

FORMS    += qtdialog.ui

#
#
# Type of compile
#
#

CONFIG(debug, debug|release) {
  message(Debug mode)
}

CONFIG(release, debug|release) {
  message(Release mode)

  #Remove all asserts and TRACE
  DEFINES += NDEBUG NTRACE_BILDERBIKKEL
}

#
#
# Platform specific
#
#

#
#
# Compiler flags
#
#
QMAKE_CXXFLAGS += -Wall -Wextra

unix {
  message(Unix)
  #Strict error handling
  QMAKE_CXXFLAGS += -std=c++11 -Werror
}

win32 {
  !static {
    message(Native Windows)
    #Allow native Windows to emit warnings without terminating
    QMAKE_CXXFLAGS += -std=c++11 #-Werror

  }

  static {
    message(Crosscompiling from Lubuntu to Windows)
    #Allow the crosscompiler to emit warnings without terminating
    QMAKE_CXXFLAGS += -std=c++11 #-Werror
  }
}

#
#
# Boost
#
#

unix {
  message(Unix dynamic link to Boost)

  LIBS += \
  -lboost_date_time \
  -lboost_filesystem \
  -lboost_program_options \
  -lboost_regex \
  -lboost_signals \
  -lboost_system
}

win32 {

  message(Windows dynamic link to Boost)

  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0

  debug {
    LIBS += ../../Libraries/boost_1_54_0/stage/lib/libboost_filesystem-mgw48-mt-d-1_54.a
    LIBS += ../../Libraries/boost_1_54_0/stage/lib/libboost_system-mgw48-mt-d-1_54.a
  }
  release {
    LIBS += ../../Libraries/boost_1_54_0/stage/lib/libboost_filesystem-mgw48-mt-1_54.a
    LIBS += ../../Libraries/boost_1_54_0/stage/lib/libboost_system-mgw48-mt-1_54.a
  }
}

#
#
# Warp's function parser
#
#
#unix {
  INCLUDEPATH += \
    ../../Libraries/fparser4.5.1

  HEADERS += \
    ../../Libraries/fparser4.5.1/extrasrc/fpaux.hh \
    ../../Libraries/fparser4.5.1/extrasrc/fptypes.hh \
    ../../Libraries/fparser4.5.1/fparser_gmpint.hh \
    ../../Libraries/fparser4.5.1/fparser.hh \
    ../../Libraries/fparser4.5.1/fparser_mpfr.hh \
    ../../Libraries/fparser4.5.1/fpconfig.hh

  SOURCES += \
    ../../Libraries/fparser4.5.1/fparser.cc \
    ../../Libraries/fparser4.5.1/fpoptimizer.cc


  OTHER_FILES += \
    ../../Libraries/fparser4.5.1/extrasrc/fp_identifier_parser.inc \
    ../../Libraries/fparser4.5.1/extrasrc/fp_opcode_add.inc
#}

#
#
# Qwt
#
#

unix {
  INCLUDEPATH += /usr/include/qwt-qt4
  LIBS += -lqwt-qt4
}

win32 {
  message(Windows: Qwt: link dynamically)
  INCLUDEPATH+= ../../Libraries/qwt-6.1.0/src
  #DEPENDPATH += ../../Libraries/qwt-6.1.0/src
  LIBS+= -L../../Libraries/qwt-6.1.0/lib

  CONFIG(release, debug|release) {
    message(Windows: Qwt: Linking to qwt)
    LIBS += -lqwt
  }

  CONFIG(debug, debug|release) {
    message(Windows: Qwt: Linking to qwtd)
    LIBS += -lqwtd
  }
}

 

 

 

 

 

./CppQtCreator_5_1/main.cpp

 

#include "qtdialog.h"
#include <QApplication>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QtDialog w;
  w.show();
  return a.exec();
}

/*


#
#
# Boost
#
#

unix {
  LIBS += \
  -lboost_date_time \
  -lboost_filesystem \
  -lboost_program_options \
  -lboost_regex \
  -lboost_signals \
  -lboost_system
}

win32 {

  #Boost libraries
  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0

  #Prevent the following error:
  #../../Libraries/boost_1_54_0/libs/program_options/src/parsers.cpp: In function 'boost::program_options::parsed_options boost::program_options::parse_environment(const boost::program_options::options_description&, const boost::function1<std::basic_string<char>, std::basic_string<char> >&)':
  #../../Libraries/boost_1_54_0/libs/program_options/src/parsers.cpp:194:36: error: 'environ' was not declared in this scope
  #DEFINES += __COMO_VERSION__


  #Boost.Data_time
  HEADERS += \
    ../../Libraries/boost_1_54_0/libs/date_time/src/gregorian/greg_names.hpp
  SOURCES += \
    ../../Libraries/boost_1_54_0/libs/date_time/src/gregorian/greg_weekday.cpp \
    ../../Libraries/boost_1_54_0/libs/date_time/src/gregorian/gregorian_types.cpp \
    ../../Libraries/boost_1_54_0/libs/date_time/src/gregorian/greg_month.cpp \
    ../../Libraries/boost_1_54_0/libs/date_time/src/gregorian/date_generators.cpp

  #Boost.Filesystem
  HEADERS += \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/windows_file_codecvt.hpp
  SOURCES += \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/codecvt_error_category.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/operations.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/path.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/path_traits.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/portability.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/unique_path.cpp \
    ../../Libraries/boost_1_54_0/libs/filesystem/src/utf8_codecvt_facet.cpp \ #Keep, comment program_options/src/utf8_codecvt_facet.cpp
    ../../Libraries/boost_1_54_0/libs/filesystem/src/windows_file_codecvt.cpp

  #Boost.Program_options
  #
  #This lib does not seem to work well together with Boost.Filesystem
  #when compiled from source like this
  #
  #SOURCES += \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/cmdline.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/config_file.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/convert.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/options_description.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/parsers.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/positional_options.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/split.cpp \
  #  #../../Libraries/boost_1_54_0/libs/program_options/src/utf8_codecvt_facet.cpp \ #Comment, keep filesystem/src/utf8_codecvt_facet.cpp
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/value_semantic.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/variables_map.cpp \
  #  ../../Libraries/boost_1_54_0/libs/program_options/src/winmain.cpp

  #Boost.Regex
  HEADERS += \
    ../../Libraries/boost_1_54_0/libs/regex/src/internals.hpp

  SOURCES += \
    ../../Libraries/boost_1_54_0/libs/regex/src/winstances.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/wide_posix_api.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/wc_regex_traits.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/w32_regex_traits.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/usinstances.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/static_mutex.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/regex_traits_defaults.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/regex_raw_buffer.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/regex_debug.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/regex.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/posix_api.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/instances.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/icu.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/fileiter.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/c_regex_traits.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/cregex.cpp \
    ../../Libraries/boost_1_54_0/libs/regex/src/cpp_regex_traits.cpp

  #Boost.System
  HEADERS += \
    ../../Libraries/boost_1_54_0/libs/system/src/local_free_on_destruction.hpp
  SOURCES += \
    ../../Libraries/boost_1_54_0/libs/system/src/error_code.cpp
}



*/

 

 

 

 

 

./CppQtCreator_5_1/qtdialog.h

 

#ifndef QTDIALOG_H
#define QTDIALOG_H

#include <QDialog>

namespace Ui {
  class QtDialog;
}

struct QwtPlotCurve;
struct QwtPlot;

class QtDialog : public QDialog
{
  Q_OBJECT
  
public:
  explicit QtDialog(QWidget *parent = 0);
  ~QtDialog();

  QwtPlotCurve * const m_curve;
  QwtPlot * const m_plot;

private:
  Ui::QtDialog *ui;

  ///FileToVector reads a file and converts it to a std::vector<std::string>
  ///From http://www.richelbilderbeek.nl/CppFileToVector.htm
  static const std::vector<std::string> FileToVector(const std::string& filename);

  ///GetBoostVersion returns the version of the current Boost library.
  ///From http://www.richelbilderbeek.nl/CppGetBoostVersion.htm
  static const std::string GetBoostVersion();

  ///GetGccVersion returns the version number of GCC currently installed.
  ///From http://www.richelbilderbeek.nl/CppGetGccVersion.htm
  static const std::string GetGccVersion();

  ///GetQtCreatorVersion obtains the version of Qt Creator
  ///Fails under Windows
  ///From http://www.richelbilderbeek.nl/CppGetQtCreatorVersion.htm
  static const std::string GetQtCreatorVersion();

  ///GetStlVersion returns the version number of the GCC STL currently installed.
  ///From http://www.richelbilderbeek.nl/CppGetStlVersion.htm
  static const std::string GetStlVersion();


};

#endif // QTDIALOG_H

 

 

 

 

 

./CppQtCreator_5_1/qtdialog.cpp

 

#include "qtdialog.h"
#include "ui_qtdialog.h"

#include <cassert>
#include <cmath>
#include <string>
#include <string>
#include <sstream>

#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/version.hpp>

#include <QLabel>
#include <QVBoxLayout>

#include "fparser.hh"

#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_point_data.h"
#include "qwt_text.h"

QtDialog::QtDialog(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::QtDialog),
  m_curve(new QwtPlotCurve("Sine")),
  m_plot(new QwtPlot(QwtText("CppQwtExample1")))
{
  ui->setupUi(this);

  assert(!this->layout());
  QLayout * const my_layout = new QVBoxLayout;
  this->setLayout(my_layout);

  #ifndef NDEBUG
  my_layout->addWidget(new QLabel("DEBUG"));
  #else
  my_layout->addWidget(new QLabel("RELEASE"));
  #endif

  my_layout->addWidget(new QLabel( ("GCC version: " + GetGccVersion()).c_str()));
  //my_layout->addWidget(new QLabel( ("Qt Creator version: " + GetQtCreatorVersion()).c_str()));
  my_layout->addWidget(new QLabel( ("STL version: " + GetStlVersion()).c_str()));
  my_layout->addWidget(new QLabel( ("Boost version: " + GetBoostVersion()).c_str()));


  {
    FunctionParser f;
    f.Parse("x * x","x");
    assert(f.GetParseErrorType()== FunctionParser::FP_NO_ERROR);
    const double xs[1] = { M_PI };
    const double y = f.Eval(xs);
    assert(f.EvalError()==0);
    my_layout->addWidget(new QLabel("Warp's function parser version: 4.5.1"));
  }
  {
    m_plot->setGeometry(0,0,640,400);
    m_plot->setAxisScale(QwtPlot::xBottom, 0.0,2.0 * M_PI);
    m_plot->setAxisScale(QwtPlot::yLeft,-1.0,1.0);
    std::vector<double> xs;
    std::vector<double> ys;
    for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0))
    {
      xs.push_back(x);
      ys.push_back(std::sin(x));
    }
    QwtPointArrayData * const data = new QwtPointArrayData(&xs[0],&ys[0],xs.size());
    m_curve->setData(data);
    m_curve->attach(m_plot);
    m_plot->replot();
    my_layout->addWidget(m_plot);
  }
}

QtDialog::~QtDialog()
{
  delete ui;
}

const std::vector<std::string> QtDialog::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;
}

const std::string QtDialog::GetBoostVersion()
{
  std::string s = BOOST_LIB_VERSION;
  std::replace(s.begin(),s.end(),'_','.');
  return s;
}

const std::string QtDialog::GetGccVersion()
{
  return
      boost::lexical_cast<std::string>(__GNUC__)
    + std::string(".")
    + boost::lexical_cast<std::string>(__GNUC_MINOR__)
    + std::string(".")
    + boost::lexical_cast<std::string>(__GNUC_PATCHLEVEL__);
}

const std::string QtDialog::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 "";
}

const std::string QtDialog::GetStlVersion()
{
  return boost::lexical_cast<std::string>(__VERSION__);
}

 

 

 

 

 

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