Ошибка LNK2019 в QT - PullRequest
       14

Ошибка LNK2019 в QT

0 голосов
/ 22 мая 2018

Вот мой код:

Mainwindow.cpp:

#include "Mainwindow.h"
#include "ui_Mainwindow.h"
#include "ContactsController.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    updateContactsList();
}

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

void MainWindow::on_addNewContactButton_clicked()
{
    ContactsController::updateContacts(
       ui->lineName->text().toStdString(),
       ui->lineNumbers->text().toStdString()
    );
    updateContactsList();
    /*std::string name(ui->lineName->text().toUtf8().constData());

    std::string numbers(ui->lineNumbers->text().toUtf8().constData());
   // ContactsManager


    std::vector<std::string> numbersVector(ContactsManager::parseNumbers(numbers));

    Contact newContact = {
        name,
        numbersVector
    };

    ContactsManager::addContact(newContact);
    updateContactsList();*/
}

void MainWindow::updateContactsList()
{
    ui->contactsList->clear();
    const QStringList itemsList(ContactsController::prepareContacts());
    ui->contactsList->addItems(itemsList);
}

ContactsController.h:

#ifndef CONTACTSCONTROLLER_H
#define CONTACTSCONTROLLER_H

#include <string>
#include <QStringList>
#include "ContactsModel.h"

class ContactsController
{
    std::vector<std::string> parseNumbers(std::string numbers);
    static std::string contactRepresentation(const Contact&);
public:
    /*static std::vector<Contact> availableContacts;
    static std::vector<Contact> readContacts();
    static void updateContacts();
    static std::vector<std::string> parseNumbers(std::string);
    static void addContact(const Contact&);*/
    static void updateContacts(const std::string&, const std::string&);
    static const QStringList prepareContacts();
};

#endif // CONTACTSCONTROLLER_H

ContactsController.cpp:

#include "ContactsController.h"

static void ContactsController::updateContacts(const std::string& name, const std::string& numbers) {
    Contact contact = {name, ContactsController::parseNumbers(numbers)};
    ContactsModel::upsert(contact);
}

std::vector<std::string> ContactsController::parseNumbers(std::string numbers)
{
    std::vector<std::string> res;

    const std::string delimiter(",");

    size_t pos = 0;
    std::string token;
    while ((pos = numbers.find(delimiter)) != std::string::npos) {
        token = numbers.substr(0, pos);
        res.push_back(token);
        numbers.erase(0, pos + delimiter.length());
    }

    return res;
}

const QStringList ContactsController::prepareContacts() {
    QStringList res;

    map<std::string, Contact> allContacts(ContactsModel::allContacts());

    map<std::string, Contact>::iterator it(allContacts.begin());
    while (it != allContacts.end()) {
        QString qstring(QString::fromUtf8(contactRepresentation(it->second)));
        res.append(qstring);
        ++it;
    }

    return res;
}

static std::string contactRepresentation(const Contact& contact) {
    std::res(contact.name + " ");
    const std::vector<std::string>& numbers(contact.numbers);
    bool previousExist(false);
    for(std::vector<T>::iterator it(numbers.begin()); it != numbers.end(); ++it) {
        /* std::cout << *it; ... */
        if(previousExist) {
            res+=";";
        }
        res+=(*it);
        previousExist = true;
    }
    return res;
}

Вот ошибки, которые я получаю:

Mainwindow.obj: -1: ошибка: LNK2019: неразрешенный внешний символ "public: static void __cdecl ContactsController :: updateContacts (класс std :: basic_string, класс std :: allocator> const &, класс std :: basic_string, класс std :: allocator> const &) "(? updateContacts @ ContactsController @@ SAXAEBV? $ basic_string @ DU? $ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ 0 @ Z) ссылка на функцию "private: void __cdecl MainWindow :: on_addNewContactButton_clicked (void)" (? on_addNewContactButton_clicked @ MainWindow @@ AEAAXXZ)

Mainwindow:-1: ошибка: LNK2019: неразрешенный внешний символ «public: статический класс QStringList const __cdecl ContactsController :: prepareContacts (void)» (? PrepareContacts @ ContactsController @@ SA? BVQStringList @@ XZ), на который есть ссылка в функции "private: void __cdecl MainWindow:: updateContactsList (void) "(? updateContactsList @MainWindow @@ AEAAXXZ)

debug \ Trofimov01.exe: -1: ошибка: LNK1120: 2 неразрешенных внешних кода

Что я здесь не так делаю?Я несколько раз проверял, что сигнатура функции одинакова в ContactsController.h и ContactsController.cpp.Здесь не должно быть ошибок связывания.

...