G
Gintoki-_-Aug. 28, 2021, 2:11 p.m.

Ошибка undefined reference to

Доброго времени суток!

Полгода назад писал один проект на Qt, получил ошибку и так и не смог разобраться что там не так.

Не могли бы вы глянуть и указать на ошибки?

Ошибки

complex.h

#ifndef COMPLEX_H
#define COMPLEX_H

#include <QtMath>

class Complex
{
    public:
        qreal real;
        qreal imag;
        bool inf;

        Complex(const qreal &a=0, const qreal &b=0, const bool &c=1);

        /*Complex(const Complex &a);

        Complex operator = (const Complex &a);*/

        //~Complex();

        static qreal norm (const Complex &a);

        static qreal abs (const Complex &a);

        static qreal arg (const Complex &a);

        static Complex conj (const Complex &a);

        Complex operator - () const;

        Complex operator + (const Complex &a) const;

        Complex operator - (const Complex &a) const;

        Complex operator * (const Complex &a) const;

        Complex operator / (const Complex &a) const;

        bool operator == (const Complex &a) const;

        bool operator != (const Complex &a) const;

        static Complex exp(const Complex &a);

        static Complex ln(const Complex &a);

        static Complex pow (const Complex &a, const Complex &b);

        static Complex sin(const Complex &a);

        static Complex cos(const Complex &a);

};

#endif

transformation.h

#ifndef TRANSFORMATION_H
#define TRANSFORMATION_H

#include "complex.h"
#include <QVector>
//#include "circle.h"

class Transformation
{
  private:
    Complex a;
    Complex b;
    Complex c;
    Complex d;
    bool e;

  public:

    //конструктор
    Transformation(const Complex &a_1 = {1,0}, const Complex &b_1 = {0, 0}, const Complex &c_1 = {0, 0}, const Complex &d_1 = {1, 0}, const bool &e_1 = 0);

    Complex Transf(const Complex &G) const;

    //оператор композиции (последовательное применение)
    Transformation operator *(const Transformation &t) const;

    //оператор итерации (последовательное примение одного преобразования несколько раз)
    Transformation operator ^(const int &k) const;

    //оператор сравнения, возвращает true если преобразования одинаковы
    bool operator == (const Transformation &t) const;

    //оператор сравнения, возвращает true если преобразования различны
    bool operator != (const Transformation &t) const;

    //поворот(центр поворота, угол)
    static Transformation rotate(const Complex &O, const qreal &ang);

    //static Transformation invers(Circle &G);

};


#endif // TRANSFORMATION_H

complex.cpp

#include "complex.h"

Complex::Complex(const qreal &a, const qreal &b, const bool &c)
    : real{a}, imag{b}, inf{c}
{

}

/*Complex::Complex(const Complex &a)
    : real{a.real}, imag{a.imag}, inf{a.inf}
{

}

Complex Complex::operator =(const Complex &a)
{
    real = a.real;
    imag = a.imag;
    inf = a.inf;
    return {a.real, a.imag, a.inf};
}
*/

/*Complex::~Complex(){
    delete real, imag, inf;
}*/

/*
{
    if (a.inf)
    {
        out << a.real;
        if (a.imag==0){
            out << "+0i";
        } else {
            if (a.imag > 0)
            {
                out << "+";
            }
            out << a.imag << "i";
        }
    }
    else
    {
        out << "∞";
    }
    return out;
}*/

qreal Complex::norm(const Complex &a)
{
    return a.real * a.real + a.imag * a.imag;
}

qreal Complex::abs(const Complex &a)
{
    return qSqrt(Complex::norm(a));
}

qreal Complex::arg(const Complex &a)
{
    if (a.real == 0)
    {
        return ((a.real > 0) - (a.real < 0)) * qAcos(-1) / 2;
    }
    else if ((a.real < 0) && (a.imag > 0))
    {
        return qAcos(-1) + qAtan(a.imag / a.real);
    }
    else
    {
        return -qAcos(-1) + qAtan(a.imag / a.real);
    }
}

Complex Complex::conj(const Complex &a)
{
    return {a.real, -a.imag, a.inf};
}

Complex Complex::operator -() const
{
    if (inf)
    {
        return {-real,-imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator+(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real + a.real, imag + a.imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator-(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real - a.real, imag - a.imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator*(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real * a.real - imag * a.imag, real * a.imag + imag * a.real};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator/(const Complex &a) const
{
    Complex out;
    if ((inf) && (a.inf))
    {
        if ((a.real == 0) && (a.imag == 0))
        {
            out={0, 0, 0};
        }
        else
        {
            Complex d = *this;
            Complex r = d * Complex::conj(a);
            out = {r.real / Complex::norm(a), r.imag / Complex::norm(a)};
        }
    }
    else if (inf)
    {
        out = {0, 0, 1};
    }

    return out;
}

bool Complex::operator==(const Complex &a) const
{
    if ((real == a.real) && (imag == a.imag) && (inf == a.inf))
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool Complex::operator!=(const Complex &a) const
{
    if ((real - a.real != 0) || (imag - a.imag != 0) || (inf - a.inf != 0))
    {
        return true;
    }
    else
    {
        return false;
    }
}

Complex Complex::exp(const Complex &a)
{
    if (a.inf)
    {
        return {qExp(a.real) * qCos(a.imag), qExp(a.real) * qSin(a.imag)};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::ln(const Complex &a)
{
    if ((a.real==0)&&(a.imag==0))
    {
        return {0,0,0};
    }
    else
    {
        return {qLn(Complex::abs(a)), qAcos(a.real / Complex::abs(a))};
    }
}

Complex Complex::pow(const Complex &a, const Complex &b)
{
    return (Complex::exp(Complex::ln(a) * b));
}

Complex Complex::sin(const Complex &a)
{
    return (Complex::exp(Complex(0, 1) * a) - Complex::exp(Complex(0, -1) * a)) / Complex(0, 2);
}

Complex Complex::cos(const Complex &a)
{
    return (Complex::exp(Complex(0, 1) * a) + Complex::exp(Complex(0, -1) * a)) / Complex(2, 0);
}

transformation.cpp

#include "transformation.h"

Transformation::Transformation(const Complex &a_1, const Complex &b_1, const Complex &c_1, const Complex &d_1, const bool &e_1)
    : a{a_1}, b{b_1}, c{c_1}, d{d_1}, e{e_1}
{

}

Complex Transformation::Transf(const Complex &G) const
{
    if (e)
    {
        //e=1 nesobstv e=0 sobstv
        return (a * Complex::conj(G) + b)/(c * Complex::conj(G) + d);
    }
    else
    {
        return (a * G + b)/(c * G + d);
    }
}

Transformation Transformation::operator *(const Transformation &t) const
{
    if(e){
        return {
            ((a * Complex::conj(t.a)) + (b * Complex::conj(t.c))),
            ((a * Complex::conj(t.b)) + (b * Complex::conj(t.d))),
            ((c * Complex::conj(t.a)) + (d * Complex::conj(t.c))),
            ((c * Complex::conj(t.b)) + (d * Complex::conj(t.d))),
            (e != t.e)
        };
    } else {
        return {
            ((a * t.a) + (b * t.c)),
            ((a * t.b) + (b * t.d)),
            ((c * t.a) + (d * t.c)),
            ((c * t.b) + (d * t.d)),
            (e != t.e)
        };
    }
}

Transformation Transformation::operator ^(const int &k) const
{
    int l=k;
    Transformation t;
    Transformation f={a, b, c, d, e};
    Transformation g={d, -b, -c, a, e};
    if(k>0){
        while(l--){
            t=t*f;
        }
    } else {
        while(l++){
            t=t*g;
        }
    }
    return t;
}

bool Transformation::operator == (const Transformation &t) const
{
    if((a==t.a)&&(b==t.b)&&(c==t.c)&&(d==t.d)&&(e==t.e)){
        return 0;
    } else {
        return 1;
    }
}

bool Transformation::operator != (const Transformation &t) const{
    if((a!=t.a)||(b!=t.b)||(c!=t.c)||(d!=t.d)||(e!=t.e)){
        return 0;
    } else {
        return 1;
    }
}

Transformation Transformation::rotate(const Complex &O, const qreal &ang)
{
    Complex g = {qreal(cos(ang)), qreal(sin(ang))};
    return {
            g,
            O - O * g,
            {0, 0},
            {1, 0},
            0
            };
}

/*Transformation Transformation::invers(Circle &G)
{
    QVector<Complex> F = G.getCenter_and_Radius();
    if (F.at(0) == Complex(2,0))
    {
        QVector<Complex> K=G.equation();
        return {
            K.at(2)/K.at(0),
            -K.at(3)/K.at(0),
            Complex(1,0),
            -Complex::conj(K.at(2)/K.at(0)),
            1
        };
    }
    else
    {
        Complex g = G.A - G.B;
        return {
            g,
            G.B * Complex::conj(G.A) - G.A * Complex::conj(G.B),
            0,
            Complex::conj(g),
            1
            };
    }
}*/

/*auto fixp()
{
        a=initializatoin
        if (e){
            if(c==Co_Z){

            } else {

            }
        } else {
            if(c==Co_Z){
                if(a==Co_1){
                    return {Co_1/Co_i};
                } else {
                    return {b/(Co_1-a),Co_1/Co_i};
                }
            } else {

            }
        }
    return {a};
}*/

pro файл

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++14

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    circle.cpp \
    complex.cpp \
    main.cpp \
    mainwindow.cpp \
    simplemenu.cpp \
    transformation.cpp \
    view.cpp

HEADERS += \
    circle.h \
    complex.h \
    mainwindow.h \
    simplemenu.h \
    transformation.h \
    view.h

FORMS += \
    mainwindow.ui \
    simplemenu.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

2
G
  • Aug. 29, 2021, 3:30 a.m.
  • (edited)

Похоже, ошибка была в pro файле: в 1 строке лишний отступ? (Можете рассказать про синтаксис pro файла?). Пойду проверять работает ли всё

    Evgenii Legotckoi
    • Oct. 11, 2021, 3:14 a.m.

    Маловероятно, скорее всего нужно было перезапустить qmake после создания файла.

      Comments

      Only authorized users can post comments.
      Please, Log in or Sign up
      Дмитрий

      C ++ - Test 004. Pointers, Arrays and Loops

      • Result:60points,
      • Rating points-1
      Дмитрий

      C++ - Тест 003. Условия и циклы

      • Result:92points,
      • Rating points8
      d
      • dsfs
      • April 26, 2024, 4:56 a.m.

      C ++ - Test 004. Pointers, Arrays and Loops

      • Result:80points,
      • Rating points4
      Last comments
      k
      kmssrFeb. 8, 2024, 6:43 p.m.
      Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
      Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
      EVA
      EVADec. 25, 2023, 10:30 a.m.
      Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
      J
      JonnyJoDec. 25, 2023, 8:38 a.m.
      Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
      G
      GvozdikDec. 18, 2023, 9:01 p.m.
      Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
      Now discuss on the forum
      G
      George13May 7, 2024, 12:27 a.m.
      добавить qlineseries в функции в функции: "GPlotter::addSeries(QString title, QVector &arr)" я вызываю метод setChart(...), я в конструктор передал адрес на QChartView элемент
      BlinCT
      BlinCTMay 5, 2024, 5:46 a.m.
      Написать свой GraphsView Всем привет. В Qt есть давольно старый обьект дял работы с графиками ChartsView и есть в 6.7 новый но очень сырой и со слабым функционалом GraphsView. По этой причине я хочу написать х…
      PS
      Peter SonMay 3, 2024, 5:57 p.m.
      Best Indian Food Restaurant In Cincinnati OH Ready to embark on a gastronomic journey like no other? Join us at App india restaurant and discover why we're renowned as the Best Indian Food Restaurant In Cincinnati OH . Whether y…
      Evgenii Legotckoi
      Evgenii LegotckoiMay 2, 2024, 2:07 p.m.
      Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Добрый день. По моему мнению - да, но то, что будет касаться вызовов к функционалу Андроида, может создать огромные трудности.
      IscanderChe
      IscanderCheApril 30, 2024, 4:22 a.m.
      Во Flask рендер шаблона не передаётся в браузер Доброе утро! Имеется вот такой шаблон: <!doctype html><html> <head> <title>{{ title }}</title> <link rel="stylesheet" href="{{ url_…

      Follow us in social networks