Qt 4.8.2. Qt Crearor выдает ошибки

121
24 сентября 2019, 20:30

начал изучать Qt. Преподаватель дал готовый код калькулятора на 4.8.2 сказал скопировать и разобрать его. Скопировал — QtCreator начал материться. В чем проблема и как ее исправить? Спасибо.

Вот код соответствующих файлов и скриншоты ошибок QtCreator

файл Calculator.cpp

#include <QtGui>
#include "Calculator.h"
Calculator::Calculator(QWidget* pwgt/*= 0*/) : QWidget(pwgt)
{
m_plcd = new QLCDNumber(12);
m_plcd->setSegmentStyle(QLCDNumber::Flat);
m_plcd->setMinimumSize(150, 50);
QChar aButtons[4][4] = {{'7', '8', '9', '/'},
                        {'4', '5', '6', '*'},
                        {'1', '2', '3', '-'},
                        {'0', '.', '=', '+'}
                       };
//Layout setup
QGridLayout* ptopLayout = new QGridLayout;
ptopLayout->addWidget(m_plcd, 0, 0, 1, 4);
ptopLayout->addWidget(createButton("CE"), 1, 3);
for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
       ptopLayout->addWidget(createButton(aButtons[i][j]), i + 2, j);
    }
}
setLayout(ptopLayout);
}
QPushButton* Calculator::createButton(const QString& str)
{
QPushButton* pcmd = new QPushButton(str);
pcmd->setMinimumSize(40, 40);
connect(pcmd, SIGNAL(clicked()), SLOT(slotButtonClicked()));
return pcmd;
}

void Calculator::calculate()
{
double  dOperand2    = m_stk.pop().toDouble();
QString strOperation = m_stk.pop();
double  dOperand1    = m_stk.pop().toDouble();
double  dResult      = 0;
if (strOperation == "+") {
    dResult = dOperand1 + dOperand2;
}
if (strOperation == "-") {
    dResult = dOperand1 - dOperand2;
}
if (strOperation == "/") {
    dResult = dOperand1 / dOperand2;
}
if (strOperation == "*") {
    dResult = dOperand1 * dOperand2;
}
m_plcd->display(dResult);
}
void Calculator::slotButtonClicked()
{
QString str = ((QPushButton*)sender())->text();
if (str == "CE") {
    m_stk.clear();
    m_strDisplay = "";
    m_plcd->display("0");
    return;
}
if (str.contains(QRegExp("[0-9]"))) {
    m_strDisplay += str;
    m_plcd->display(m_strDisplay.toDouble());
}
else if (str == ".") {
    m_strDisplay += str;
    m_plcd->display(m_strDisplay);
}
else {
    if (m_stk.count() >= 2) {
        m_stk.push(QString().setNum(m_plcd->value()));
        calculate();
        m_stk.clear();
        m_stk.push(QString().setNum(m_plcd->value()));
        if (str != "=") {
            m_stk.push(str);
        }
    }
    else {
        m_stk.push(QString().setNum(m_plcd->value()));
        m_stk.push(str);
        m_strDisplay = "";
        m_plcd->display("0");
    }
}
}

Скриншоты с ошибками файла Calculator.cpp

Файл Calculator.h

#ifndef _Calculator_h_
#define _Calculator_h_
#include <QWidget>
#include <QStack>
class QLCDNumber;
class QPushButton;
class Calculator : public QWidget {
  Q_OBJECT
  private:
  QLCDNumber*     m_plcd;
  QStack<QString> m_stk;
  QString         m_strDisplay;
  public:
  Calculator(QWidget* pwgt = 0);
  QPushButton* createButton(const QString& str);
  void         calculate   (                  );
  public slots:
  void slotButtonClicked();
  };
  #endif  //_Calculator_h_

Скриншоты с ошибками файла Calculator.h

Файл Calculator.pro

 TEMPLATE     = app
 HEADERS         = Calculator.h
 SOURCES         = Calculator.cpp main.cpp
 win32:TARGET = ../Calculator

Возможно проблема в win32:TARGET У меня Х64 и если я правильно понял в этой строке путь к проекту нужен?

Файл main.cpp

 #include <QApplication>
 #include "Calculator.h"
 int main(int argc, char** argv)
{
QApplication app(argc, argv);
Calculator   calculator;
calculator.setWindowTitle("Calculator");
calculator.resize(230, 200);
calculator.show();
return app.exec();
}

Скриншот с ошибками

Ошибки при сборке

Страница проекты

Сриншот, после добавления 4.8.2

Связанный вопрос с ошибкой после сборки тут

READ ALSO
Ошибка Qt. Untested Windows version 6.2 detected

Ошибка Qt. Untested Windows version 6.2 detected

Программа пытается запуститься, но не запускаетсяКомпилируется с предупреждением что не тестировалось в Windows 8, но у меня 10

126
Перевод из Java в с++

Перевод из Java в с++

Имеется такой класс:

138
Как реализовать сохранение SurfaceView в файл?

Как реализовать сохранение SurfaceView в файл?

Я рисую прямоугольники с использованием Canvas, динамически перемещаю и изменяю SurfaceView, я использую кнопку для сохранения("Save")

161
Вложеный масив в Retrofit

Вложеный масив в Retrofit

Не часто работал с Retrofit-м, поэтому еще плохо знаю всеНедавно добавил в бекенд пагинацию и следовательно в клиентов изменился json ответ

143