Simplified the code to make it easier to deal with the problem. There is a class described in mainwindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QFormLayout> #include <QLabel> #include <QLineEdit> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: void Menu1(); void NZER_N_B(int &n); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H The NZER_N_B (int & n) function should be implemented in a separate .cpp file; it is called in the main file.
nzer_n_b.cpp:
#include "mainwindow.h" void MainWindow::NZER_N_B(int &n) { n = 1770; } mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->pb1, SIGNAL(clicked(bool)), this, SLOT(Menu1())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::Menu1() { int n; NZER_N_B(n); } But with this implementation errors LNK1120,2001,2019 appear (reference to an unresolved element). But if you write the implementation of this function in the header file and connect it accordingly. That is no error, but not so right, as far as I know. So, the question is how to shove the implementation of the code in cpp and so that errors do not occur?