Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Global Functions and Variables in shared Library
Forum Updated to NodeBB v4.3 + New Features

Global Functions and Variables in shared Library

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    ranger0
    wrote on last edited by
    #1

    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:

    comp.h
    @
    #ifndef COMP_H
    #define COMP_H

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

    extern QString var1;
    extern int var2;

    #endif COMP_H
    @

    comp.cpp
    @
    #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?

    Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AquilaDev
      wrote on last edited by
      #2

      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)..

      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