Results 1 to 12 of 12

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    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

    Ha! Triumphed too early...
    now it compiles fine, but since I instantiated MainWindow within void Dialog:n_btnSend_clicked(), it seems that it dies after leaving the Function without writing to MainWindow's private variables.
    Debugging the Function in Dialog returns exactly the values entered, debugging the MainWindow's variables show them empty. I must be totally blind, but I don't see what's going wrong here.
    QString myTextString within Dialog: "Blabberdiblub"
    QString myTextString within MainWindow: ""
    int myIntegerzahl in Dialog: 11
    int myIntegerzahl in Mainwindow: 2 (seems to be a value-by-chance).

    I'm confused...

    These are my Methods in mainwindow.cpp:
    Qt Code:
    1. // Austausch-Methoden
    2. void MainWindow::setMyTextString(QString textstring)
    3. {
    4. myTextString = textstring;
    5. qDebug() << myTextString;
    6. }
    7.  
    8. QString MainWindow::getMyTextString()
    9. {
    10. return myTextString;
    11. }
    12.  
    13. void MainWindow::setMyIntegerZahl(int integerzahl)
    14. {
    15. myIntegerZahl = integerzahl;
    16. qDebug() << "myInt: " << myIntegerZahl << ", Int: " << integerzahl;
    17. }
    18.  
    19. int MainWindow::getMyIntegerZahl()
    20. {
    21. return myIntegerZahl;
    22. }
    To copy to clipboard, switch view to plain text mode 

    ...and this is how I call them in my Dialog:
    Qt Code:
    1. void Dialog::on_btnSend_clicked()
    2. {
    3. MainWindow myMainWindow; // Wichtig: MainWindow instanzieren, sonst Compilerfehler!!!
    4.  
    5. QString textstring = this->le_myTextString->text();
    6. myMainWindow.setMyTextString(textstring);
    7. myMainWindow.setMyIntegerZahl(this->spb_myIntegerZahl->value());
    8.  
    9. this->close();
    10. }
    To copy to clipboard, switch view to plain text mode 

    ...at last, this is my class definitions for MainWindow:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "dialog.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18. QString getMyTextString();
    19. void setMyTextString(QString textstring);
    20. int getMyIntegerZahl();
    21. void setMyIntegerZahl(int integerzahl);
    22.  
    23. private slots:
    24. void on_btnDialog_clicked();
    25. void on_btnUebertrag_clicked();
    26.  
    27. private:
    28. Ui::MainWindow *ui;
    29. Dialog *myDialog;
    30. QString myTextString; // Ablage für Text aus dem Dialog
    31. int myIntegerZahl; // Ablage für Integer aus dem Dialog
    32. };
    33.  
    34. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    aahh - sorry Lykurg, I didn't see you have already pointed to that failure. I'll give it a thought and try to rewrite that crap!
    Last edited by mbergmann-sh; 20th February 2013 at 14:50.

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.