Results 1 to 12 of 12

Thread: Saving Values from a Dialog to MainWindow - "cannot call member function w/o an objec

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Saving Values from a Dialog to MainWindow - "cannot call member function w/o an o

    Hi that is basic OOP!
    In Dialog:n_btnSend_clicked() you create a *new* instance of MainWindow which has no connect with the instance of MainWindow from which you execute the dialog. Again define getter functions in the dialog, and after the dialog is finished use them to alter the MainWindow. Have a second look at my example.

  2. #2
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Saving Values from a Dialog to MainWindow - "cannot call member function w/o an o

    didn't see you had already pointed to that failure. I'll give it a thought and try to rewrite that crap after overlooking your example. Thanks a lot!

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

    Default Re: Saving Values from a Dialog to MainWindow - "cannot call member function w/o an o

    I don't know what your dialog is supposed to be used and what its relation to MainWindow is but if what Lykurg suggested is somehow not an option for you (although it is the best solution possible), another solution would be to pass a pointer to MainWindow to the dialog. However, again, from OOP perspective, it is better to query a value from the dialog and set it on the main window from outside of the dialog.
    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.


  4. The following user says thank you to wysota for this useful post:

    mbergmann-sh (20th February 2013)

  5. #4
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Saving Values from a Dialog to MainWindow - "cannot call member function w/o an o

    I'm writing on a small alarm watch app consisting of a main window showing times and allowing to start a predefined alarm time, and some user dialogs fpr setting up different alarm tunes (as mp3) and entering events to be shown on wake time. This so far is what I'm working on. Since I need to store the values of those Dialogs in the main window, I thought it as a good idea soing this in the MainWindow class private vars. I wanted to have them central, because of the need of writing them into a presets file and because they are njeeded by the main window in order to do its job. The example code above, however, is a simplified rewrite mirroring my problem - not the app I'm working on. Since I'm relatively new to C++ I expect more quirks and quarks to come there...

    I worked myself through a German book titled "C++ in 21 Tagen", also through "The independant Qt tutorial" and the Blanchette Book on Qt, and I have some knowledge in C from my Amiga times.
    Nevertheless, i see there's more needed to fully understand C++'ing with Qt. Some concepts still confuse me, since I'm still thinking in more procedural terms. Once after a while I hope it'll change to more OOP thinking, but I have to get used to it. Guess there's more practice to be done...
    I'll start giving it a try with both possibilities in some test projects: handing a pointer to MainWindow and using getter functions. The last was what I thought I did, but obviously they are needed in the Dialog - and I implemented them in MainWindow.

    Thanks a lot for all your hints! This seems to be a very friendly forum.

Similar Threads

  1. Cannot call member function without object
    By ehntun in forum Qt Programming
    Replies: 0
    Last Post: 24th October 2012, 07:09
  2. How to call member function from int main()
    By GussieBartlett in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2012, 20:06
  3. to call member function
    By vinayaka in forum General Programming
    Replies: 5
    Last Post: 1st July 2011, 13:48
  4. cannot call member function without object
    By been_1990 in forum Qt Programming
    Replies: 11
    Last Post: 23rd October 2010, 17:12
  5. How to call the C++ member function from the JScript
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2008, 10:13

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.