É um projeto simples com finalidade de aprender a usar o subprojetos.
Erros q acontecem:
C:\Projetos-Qt\testeSubdir-build-desktop-Qt_4_8_0_for_Desktop\mainwindow/../../testeSubdir/mainwindow/mainwindow.cpp:15: undefined reference to `functions::functions()’
debug/mainwindow.o:C:\Projetos-Qt\testeSubdir-build-desktop-Qt_4_8_0_for_Desktop\mainwindow/../../testeSubdir/mainwindow/mainwindow.cpp:31: undefined reference to `functions::sqrt(int)’
fontes:
functions.pro
HEADERS += \
functions.h
SOURCES += \
functions.cpp \
main.cpp
functions.h
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <QObject>
class functions : public QObject
{
Q_OBJECT
public:
functions();
qint32 sqrt(qint32 i1);
signals:
public slots:
};
#endif // FUNCTIONS_H
functions.cpp
#include "functions.h"
functions::functions()
{
}
qint32 functions::sqrt(qint32 i1)
{
return i1 * i1;
}
mainwindow.pro
QT += gui
INCLUDEPATH += ../functions
HEADERS += \
mainwindow.h
SOURCES += \
mainwindow.cpp \
main.cpp
OTHER_FILES += \
../functions/functions.pro
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
class QLineEdit;
class QPushButton;
class QLabel;
class QHBoxLayout;
class functions;
class mainWindow : public QWidget
{
Q_OBJECT
private:
QLineEdit *_editValor;
QPushButton *_btnSqrt;
QLabel *_lblResult;
QHBoxLayout *mainLayout;
functions *fs;
public:
explicit mainWindow(QWidget *parent = 0);
signals:
private slots:
void executar();
public slots:
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include <QLabel>
#include<QPushButton>
#include<QLineEdit>
#include <QHBoxLayout>
#include "functions.h"
mainWindow::mainWindow(QWidget *parent) :
QWidget(parent)
{
_editValor = new QLineEdit;
_btnSqrt = new QPushButton;
_lblResult = new QLabel("Result");
fs = new functions;
mainLayout = new QHBoxLayout();
mainLayout->addWidget(_editValor);
mainLayout->addWidget(_btnSqrt);
mainLayout->addWidget(_lblResult);
setLayout(mainLayout);
connect(_btnSqrt, SIGNAL(clicked()), this, SLOT(executar()));
}
void mainWindow::executar(){
qint32 i1,i2;
i1 = _editValor->text().toInt();
i2 = fs->sqrt(i1);
_lblResult->setText(QString::number(i2));
}
main.cpp do subprojeto mainwindow
#include <QApplication>
#include <QStringList>
#include <QDebug>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainWindow *mainW = new mainWindow();
qDebug() << 0;
mainW->show();
return app.exec();
}
↧