Results 1 to 11 of 11

Thread: How to use an external variable ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to use an external variable ?

    both "alternate defintion 1" and "alternate defintion 2" are ok, either one of these will work, you should be getting the qDebug() messages, Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. (check "Application Ouput" tab is using Qt Creator)

  2. #2
    Join Date
    Nov 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: How to use an external variable ?

    Quote Originally Posted by Santosh Reddy View Post
    both "alternate defintion 1" and "alternate defintion 2" are ok, either one of these will work, you should be getting the qDebug() messages, Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. (check "Application Ouput" tab is using Qt Creator)
    The qDebug() output from the Dummy class functions is not showing in Application Output.
    But when I use qDebug() from my main function, e.g. if I add a public QString to the Dummy class, set its value in the Dummy constructor and access and output it with qDebug() from 'main', then it works.
    I forgot to mention that I had done this too.

    Quote Originally Posted by squidge View Post
    You may wish to research singletons.
    Well, I stumbled on this thread when posting this.
    The singleton code looks a bit cumbersome to me. Does it have any intrinsic advantages or is it just a work-around to avoid global variables ? Are global variables just poorly implemented in C++ ?
    I'd just like to understand why it's good to use singletons.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to use an external variable ?

    does your .pro file anything more than this?
    Qt Code:
    1. HEADERS += \
    2. data.h
    3.  
    4. SOURCES += \
    5. data.cpp \
    6. main.cpp
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: How to use an external variable ?

    My project file looks like this:

    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2010-11-25T17:13:18
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. TARGET = Test
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. mainwindow.cpp \
    15. data.cpp \
    16. ssvector.cpp
    17.  
    18. HEADERS += mainwindow.h \
    19. data.h \
    20. ssvector.h
    21.  
    22. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    For the current test I've outcommented all calls to mainwindow and ssvector (in the source code), as they were from earlier tests and were only still in there for later use.

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to use an external variable ?

    test with the .pro file posted my me...

Similar Threads

  1. variable
    By Atuti2009 in forum Qt Programming
    Replies: 8
    Last Post: 18th November 2009, 10:04
  2. Signal from variable
    By waynew in forum Newbie
    Replies: 2
    Last Post: 18th November 2009, 02:18
  3. QT and variable scope
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 22:32
  4. Getting Type of an variable
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2007, 16:37
  5. global variable
    By Shuchi Agrawal in forum General Programming
    Replies: 10
    Last Post: 15th February 2007, 05:19

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.