Results 1 to 20 of 28

Thread: How to use external source code in Qt creator?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    102
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to use external source code in Qt creator?

    Hi guys. I'm new to Qt an C++. I started developing an app on Windows platform Qt 5.1.1 Qt Creator v. 2.8.1 and would like to include some external source code in my project. So to learn how to do it, I wrote a simple c program consisting of 3 files, elab.cpp
    Qt Code:
    1. #include <iostream>
    2. #include "mat.h"
    3.  
    4. int sumup(int a, int b) {
    5. return (a + b);
    6. }
    7.  
    8. int main() {
    9. using namespace std;
    10.  
    11. int a = precalc(3,4);
    12. cout << "The sum of 3 and 4 is " << a;
    13.  
    14. int c = sumup(6,2);
    15. cout << "The sum of 6 and 2 is " << c;
    16.  
    17. return 0;
    18. }
    To copy to clipboard, switch view to plain text mode 
    mat.h
    Qt Code:
    1. #ifndef ADD_H
    2. #define ADD_H
    3.  
    4. int precalc(int x, int y);
    5.  
    6. #endif
    To copy to clipboard, switch view to plain text mode 
    and mat.cpp
    Qt Code:
    1. int precalc(int x, int y) {
    2. return (x + y);
    3. }
    To copy to clipboard, switch view to plain text mode 
    If I compile both cpp-s to exe with mingw the program runs ok. Now I wonder how do I include it in my new Qt app. I want for instance invoke my function "precalc" to be precise. So far I tried to alter the pro file by adding lines like
    Qt Code:
    1. SOURCES += "C:\Users\myuser\Documents\elab_c_proj"
    2. INCLUDEPATH += "C:\Users\myuser\Documents\elab_c_proj"
    3. LIBS += "C:\Users\myuser\Documents\elab_c_proj"
    4. HEADERS += "C:\Users\myuser\Documents\elab_c_proj"
    To copy to clipboard, switch view to plain text mode 
    I realized that adding just the INCLUDEPATH directive is enough to get access to my function when coding. However the problem arises when I try to build the new qt app, compiler/linker don't know how, tells me somehing like "undefined reference to precalc". Since I'm new to C++ I'm not sure I understand the concept correctly, so my questions are:
    1)what am I missing, doing wrong?
    2)is it enough to just add the source code (cpp and h files) via INCLUDEPATH and the qmake knows how to build my external source code to final qt app binary staticaly?
    3)or must my external app be precompiled first (say outside qt creator) like a lib file so that the qmake knows how to link to it?
    4) can I make a kind of dynamic "dll" from my external app? How would I refer to it in this case from qt app?

    Much thanks in advance for your help,

    best regard, Arcull

  2. The following user says thank you to arcull for this useful post:

    b06 (16th April 2015)

Similar Threads

  1. Qt Creator Source code export from Qt Creator
    By Gera777 in forum Qt Tools
    Replies: 2
    Last Post: 17th May 2013, 14:21
  2. Source code to *.ui
    By Zergi in forum Qt Tools
    Replies: 3
    Last Post: 28th September 2011, 18:12
  3. no source code
    By banlinhtienphong in forum General Programming
    Replies: 1
    Last Post: 25th July 2011, 17:19
  4. Qt Creator How to make Creator be aware of the Qt source code project?
    By kartwall in forum Qt Tools
    Replies: 5
    Last Post: 27th September 2010, 08:39
  5. Where is the source code?
    By Fletcher in forum Newbie
    Replies: 1
    Last Post: 10th December 2009, 20:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.