Results 1 to 8 of 8

Thread: QString class global

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QString class global

    how can i access a QString ill show my code on how im trying to do this

    bottom.h

    Qt Code:
    1. extern QString *buttonFV;
    To copy to clipboard, switch view to plain text mode 

    then in bottom.cpp

    Qt Code:
    1. while(iconmodel->query().next())
    2. {
    3. buttonFV = iconmodel->query().value(0).toString(); // String I'm Tring to get the value from in a slot
    4.  
    5. emit next_DoStyle();
    6.  
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    SLOT in bottom.cpp

    Qt Code:
    1. void ttmbottom::do_Style()
    2. {
    3.  
    4. QString bttnPath;// = QApplication::applicationDirPath();
    5. bttnPath = "/home/dev/ttm/directory/icon/";
    6. bttnPath += buttonFV; // trying to use it here !!!!!
    7.  
    8.  
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    if anyone can help me solve this issue i always have problems trying to use the data i have stored

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString class global

    Why You don't define slot as
    Qt Code:
    1. void ttmbottom::do_style(QString);
    To copy to clipboard, switch view to plain text mode 
    and then emit signal as
    Qt Code:
    1. emit next_DoStyle(iconmodel->query().value(0).toString());
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QString class global

    Sorry would you be able to show a little example as im testing it with mine and cant seem to get it working

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString class global

    First show definition of class ttmbottom. Then I will be able to modify.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QString class global

    The code as presented should not compile. Regardless of which compilation unit contains buttonFV, buttonFV is a pointer to a QString not a QString. Line 2 of the first and line 6 of the second bottom.cpp are trying to use pointer to a QString as if it were a QString.

  6. #6
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QString class global

    Quote Originally Posted by ChrisW67 View Post
    The code as presented should not compile. Regardless of which compilation unit contains buttonFV, buttonFV is a pointer to a QString not a QString. Line 2 of the first and line 6 of the second bottom.cpp are trying to use pointer to a QString as if it were a QString.
    any work arounds you suggest ?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QString class global

    You cannot "work around" invalid C++ syntax: you just have to correct it. Either make buttonFV an actual QString, or change everything that uses it to expect a pointer to a QString.

  8. #8
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QString class global

    ok thanks ill change everything to expect a pointer

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2011, 15:42
  2. Replies: 2
    Last Post: 21st October 2010, 07:03
  3. How to declare global variable outside a class?
    By babygal in forum Qt Programming
    Replies: 2
    Last Post: 26th August 2010, 08:35
  4. QString constants in a class
    By darkadept in forum Qt Programming
    Replies: 12
    Last Post: 2nd November 2007, 08:52
  5. How to pass a QString to another class ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2006, 20:16

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.