Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Portuguese
  4. Duvidas ao usar subproject, projeto compila mas quando um faz referencia a outro não compila

Duvidas ao usar subproject, projeto compila mas quando um faz referencia a outro não compila

Scheduled Pinned Locked Moved Portuguese
6 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    carlossilva
    wrote on last edited by
    #1

    É 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();
    }
    @

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rodrigocg
      wrote on last edited by
      #2

      da uma olhada nesse projeto:

      http://www.4shared.com/rar/ZzZ_fY8W/balanca.html

      antes de compilar veja o arquivo: "leia antes de compilar.txt"

      qualquer coisa pergunta...

      1 Reply Last reply
      0
      • C Offline
        C Offline
        carlossilva
        wrote on last edited by
        #3

        Ola, Rodrigocg, acho que voce se enganou, o link que passou só tem um programa ja compilado e sem o txt que tu menciona

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rodrigocg
          wrote on last edited by
          #4

          desculpe, passei o link errado...
          http://www.4shared.com/rar/0N4xR644/BalancaGF.html

          1 Reply Last reply
          0
          • C Offline
            C Offline
            carlossilva
            wrote on last edited by
            #5

            Obrigado Rodrigo irei estudar estes fontes

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rodrigocg
              wrote on last edited by
              #6

              Só comentando o que voce publicou, em um projeto de subprojects voce tem que ter um com a funcao "main" e que seja do tipo app... e em cada subproject vc tem que especificar qual vai ser o resultado da compilacao... se eh uma dll ou um aplicativo... No seu projeto functions.pro e mainwindow.pro voce nao trabalhou isso direito...

              procure sobre o comando $$PWD ele especifica o diretorio principal do projeto, e a variavel DESTDIR, que especifica o local onde os binarios serao salvos aposa compilacao...

              vc tambem pode especivicar $$DESTDIR para, por exemplo declarar bibliotecas compiladas pelo projeto.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved