Results 1 to 20 of 22

Thread: Accessing same variable from multiple windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    44
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android
    Thanks
    9

    Default Re: Accessing same variable from multiple windows

    okay here is the deal
    it works with integers .
    suppose I make I=54 in mainwindow and print I in another window , it shows 54.
    but it doesn't work with QStrings.
    when I acesss qstring q from dialog 'dialog' , it show "" ;

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Accessing same variable from multiple windows

    It works with QString. If it doesn't work for you then you did something wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2012
    Posts
    197
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 41 Times in 33 Posts

    Default Re: Accessing same variable from multiple windows

    Hello Wysota,
    Just a note, since there are two threads for the same user about the same topic, even having the same title , why dont you move them into one thread ?
    that's the other thread Accessing the same variable from multiple windows.
    It would be better instead of going through to the two threads every now and then.
    Thanks in advance Sir.
    Best Regards.
    Last edited by toufic.dbouk; 9th October 2013 at 10:42.

  4. #4
    Join Date
    May 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Accessing same variable from multiple windows

    Hey guys!

    I have sort of the same question as harvey_slash. Whenever you press the button "add" in my MainWindow it will open a dialog in which you can fill in some line-edits. Each of the line-edits will be assigned to a specific QString variable. And all of those QStrings will be put into a class of my own making. Then, whenever I post the "save" button whithin the dialog I would like it to put that object with the QStrings into a QVector that I have created in my MainWindow. I am struggling unfortunately with sending that object to my MainWindow. Can any of you please help me out?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Accessing same variable from multiple windows

    If you have a modal dialog, just add a getter function and call it when exec() returns.
    If you have a non-modal dialog, emit the value with a custom signal.

    Cheers,
    _

  6. #6
    Join Date
    May 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Accessing same variable from multiple windows

    Thanks for your response!

    So, if I understand correctly, you can only send one value at a time. It isn't possible for me to send an entire object holding more variables using the signal slot mechanism?

    Thanks!

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Accessing same variable from multiple windows

    Quote Originally Posted by MartijnKor View Post
    So, if I understand correctly, you can only send one value at a time.
    No.
    A signal can have multiple arguments and the argument types can be any custom class.

    Quote Originally Posted by MartijnKor View Post
    It isn't possible for me to send an entire object holding more variables using the signal slot mechanism?
    Of course it is. That's what my previous comment said.

    Cheers,
    _

Similar Threads

  1. multiple definitoin of variable
    By saman_artorious in forum Qt Programming
    Replies: 6
    Last Post: 22nd April 2013, 19:47
  2. Multiple definition of a variable?
    By T0bi4s in forum Newbie
    Replies: 5
    Last Post: 14th January 2010, 22:13
  3. Multiple File Data accessing
    By hasnatzaidi in forum Newbie
    Replies: 1
    Last Post: 28th October 2009, 16:34
  4. Replies: 6
    Last Post: 25th December 2008, 05:58
  5. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 10:50

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.