Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Qt -Weffc++ and Qt

 

-Weffc++ and Qt describes how the compile warning -Weffc++ goes together smoothly with Qt. The goal is to be able to compile cleanly at high warning levels [1], because we prefer compile errors to runtime errors [2].

 

 

There are some drawbacks following this way:

 

 

 

 

 

 

 

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: CppWeffcppAndQt.pro

 

QT       += core gui
QMAKE_CXXFLAGS += -Weffc++ -Werror
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CppWeffcppAndQt
TEMPLATE = app
SOURCES += main.cpp\
        dialog.cpp
HEADERS  += dialog.h
FORMS    += dialog.ui

 

 

 

 

 

dialog.h

 

#ifndef DIALOG_H
#define DIALOG_H

#pragma GCC diagnostic ignored "-Weffc++"
#include "ui_dialog.h"
#pragma GCC diagnostic pop

class Dialog : public QDialog
{
  Q_OBJECT
  
public:
  explicit Dialog(QWidget *parent = 0);
  
private slots:
  void on_pushButton_clicked();

private:
  Ui::Dialog ui;
};

#endif // DIALOG_H

 

 

 

 

 

dialog.cpp

 

#include <vector>
#include <string>

#pragma GCC diagnostic ignored "-Weffc++"
#include "dialog.h"
#pragma GCC diagnostic pop

Dialog::Dialog(QWidget *parent) :
  QDialog(parent),
  ui(Ui::Dialog())
{
  ui.setupUi(this);
}

void Dialog::on_pushButton_clicked()
{
  const std::string s = ui.label->text().toStdString() + ".";

  ui.label->setText(QString(s.c_str()));
}

 

 

 

 

 

main.cpp

 


#pragma GCC diagnostic ignored "-Weffc++"
#include <QApplication>
#include "dialog.h"
#pragma GCC diagnostic pop

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

 

 

 

 

 

References

 

  1. Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 1: 'Compile cleanly at high warning levels'.
  2. Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Item 14: 'Prefer compile- and link-time errors to run-time errors'.

 

 

 

 

 

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