Qt World Summit: Submit your Presentation

Global Functions and Variables in shared Library

  • Hi folks,

    I'd like to use some global functions and variables.

    At first time, I've done that using a header and .cpp files which was included in all application files.

    But now, I'd like to use it as a shared library.

    The files are like this:

    #ifndef COMP_H
    #define COMP_H

    extern void func1();
    extern void func2();

    extern QString var1;
    extern int var2;

    #endif COMP_H

    #include comp.h

    void func1()

    void func2()

    QString var1;
    int var2;

    I've seen same instructions at http://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application but it seems to work just to classes.

    Does any one knows how to do that?


  • just use it like that:
    @extern int var = 0;
    extern QString aa = "";@

    then use it in your cp file like any other var.. but don't re-initialize them, not like what you wrote..

    Also... avoid extern and static use in Oriented object languages... classes are here to make everything easier, when you're using global variable you're breaking it. (It's like never use private statement in classes)..

Log in to reply