Results 1 to 8 of 8

Thread: Why my setter don't work?

  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Angry Why my setter don't work?

    Hello World!

    I'm really sorry guys, I know that this is not really a Qt relatedt question, but I don't know any better forum where are so many C++ specialist then here ...

    I have a class, it's called 'Barverkauf' and until today everything is doing well.

    barverkauf.h
    Qt Code:
    1. class Barverkauf : public QDialog, public Ui::UiBarverkauf
    2. {
    3. Q_OBJECT
    4.  
    5. MainWindow *myMainWindow;
    6.  
    7. public:
    8. Barverkauf( MainWindow*, QString currentUser );
    9.  
    10. // some other stuff follows ...
    To copy to clipboard, switch view to plain text mode 

    barverkauf.cpp

    Qt Code:
    1. #include "barverkauf.h"
    2.  
    3. Barverkauf::Barverkauf ( MainWindow *pMainWindow, QString currentUser )
    4. : myMainWindow( pMainWindow )
    5. {
    6. frameHome = new QFrame( myMainWindow->centralwidget );
    7. setupUi( frameHome );
    8. frameHome->show();
    9.  
    10. // some other stuff follows ...
    11. }
    To copy to clipboard, switch view to plain text mode 

    ui_barverkauf.h

    Qt Code:
    1. class Ui_UiBarverkauf
    2. {
    3. public:
    4. // some other stuff ...
    5. QTableWidget *tableWidgetBarverkauf;
    6. // some other stuff ...
    To copy to clipboard, switch view to plain text mode 

    May be the code is not pefect - I'm still a beginner - but I can add, edit and delete lines to/from the tableWidgetBarverkauf very well..



    But then I've tried to implement a barcode-reader, and now I have a problem:

    I've created:

    readbarcode.h
    Qt Code:
    1. class ReadBarcode : public QDialog, private Ui::UiReadBarcode
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. //ReadBarcode( QWidget *parent = 0 );
    7. ReadBarcode();
    8. // some other stuff ...
    9. private:
    10. Barverkauf *barverkauf;
    To copy to clipboard, switch view to plain text mode 

    and

    readbarcode.cpp
    Qt Code:
    1. ReadBarcode::ReadBarcode()
    2. {
    3. setupUi( this );
    4. //some other stuff ...
    5.  
    6. barverkauf = new Barverkauf;
    7. }
    To copy to clipboard, switch view to plain text mode 


    Here i've tried to call the setter in barverkauf.cpp ...
    Qt Code:
    1. void ReadBarcode::addArtikel()
    2. // some other stuff ...
    3. barverkauf->addPos( id, artikel, menge, einzel );
    4. // some other stuff ...
    To copy to clipboard, switch view to plain text mode 

    Then I've added a second constructor to class Barverkauf like this:

    barverkauf.h
    Qt Code:
    1. class Barverkauf : public QDialog, public Ui::UiBarverkauf
    2. {
    3. Q_OBJECT
    4.  
    5. MainWindow *myMainWindow;
    6.  
    7. public:
    8. Barverkauf( MainWindow*, QString currentUser );
    9. Barverkauf();
    To copy to clipboard, switch view to plain text mode 

    barverkauf.cpp

    Qt Code:
    1. #include "barverkauf.h"
    2.  
    3. Barverkauf::Barverkauf ( MainWindow *pMainWindow, QString currentUser )
    4. : myMainWindow( pMainWindow )
    5. {
    6. frameHome = new QFrame( myMainWindow->centralwidget );
    7. setupUi( frameHome );
    8. frameHome->show();
    9.  
    10. // some other stuff follows ...
    11. }
    12.  
    13. Barverkauf::Barverkauf()
    14. {
    15. }
    To copy to clipboard, switch view to plain text mode 

    and a setter like this:

    Qt Code:
    1. void Barverkauf::addPos( QString id, QString artikel, QString menge, QString einzel )
    2. {
    3. qDebug() << id;
    4. qDebug() << artikel;
    5. qDebug() << menge;
    6. qDebug() << einzel;
    7.  
    8. int row = tableWidgetBarverkauf->rowCount();
    9.  
    10. qDebug() << "row" << row;
    11.  
    12. // Eine neue Reihe hinzufuegen ...
    13. tableWidgetBarverkauf->insertRow( row );
    14. tableWidgetBarverkauf->setItem( row, 0, new QTableWidgetItem() );
    15. tableWidgetBarverkauf->setItem( row, 1, new QTableWidgetItem() );
    16. // some other code ...
    To copy to clipboard, switch view to plain text mode 

    Looks like the code is working now, but the lines are added to the second tableWidgetBarverkauf I have created in my copy-constructor.

    In other words, it's working, but I can't see it on the screen!

    Sorry, but I've never worked with a second constructor before ...
    Last edited by gboelter; 8th November 2009 at 07:34. Reason: updated contents

  2. #2
    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: Why my setter don't work?

    The three lines of code in your original constructor set up the Qt Designer UI and show it. When you create another instance of the Barverkauf class with the bare constructor none of this UI setup is done and this is probably why you are not seeing anything.

    I'm no C++ guru, and I'm not entirely sure what you are expecting to see/have happen.

  3. The following user says thank you to ChrisW67 for this useful post:

    gboelter (8th November 2009)

  4. #3
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why my setter don't work?

    Quote Originally Posted by ChrisW67 View Post
    The three lines of code in your original constructor set up the Qt Designer UI and show it. When you create another instance of the Barverkauf class with the bare constructor none of this UI setup is done and this is probably why you are not seeing anything.
    Thanks for the reply.

    This was my idea too, but without these lines my setter can't see the tableWidget.

    I'm sure it's easy to fix, but I don't have an idea how ...

  5. #4
    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: Why my setter don't work?

    At line 6 in readbarcode.cpp you create a new, independent instance of the Barverkauf class using the constructor Barverkauf::Barverkauf(), which does not set up the UI in that instance as far as I can tell. ReadBarcode uses this private instance of the Barverkauf.

    Are you trying to get two separate Barverkauf windows or have the ReadBarcode class access an existing one?

  6. The following user says thank you to ChrisW67 for this useful post:

    gboelter (8th November 2009)

  7. #5
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why my setter don't work?

    Quote Originally Posted by ChrisW67 View Post
    Are you trying to get two separate Barverkauf windows or have the ReadBarcode class access an existing one?
    No, there is only one window 'Barverkauf'. From there I would like to open a seperate snall gui - class ReadBarcode() - for my scan results.

    After each scan, if the scan was successfull, the data should be added to the tableWidget inside the window 'Barverkauf".

  8. #6
    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: Why my setter don't work?

    Your ReadBarcode class should be given some sort of access to the model that your table view is coming from. You could create your ReadBarcode objects with a pointer Barverkauf object or directly to the TableWidget/model you wish to update:
    Qt Code:
    1. class ReadBarcode : public QDialog, private Ui::UiReadBarcode
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. //ReadBarcode( QWidget *parent = 0 );
    7. ReadBarcode(Barverkauf *b);
    8. // some other stuff ...
    9. private:
    10. Barverkauf *barverkauf;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ReadBarcode::ReadBarcode(Barverkauf *b)
    2. {
    3. setupUi( this );
    4. //some other stuff ...
    5.  
    6. barverkauf = b;
    7. }
    To copy to clipboard, switch view to plain text mode 
    and leave the rest of ReadBarcode unchanged.

    You could consider separating the model underlying the QTableWidget (making it a QTableView) and share that model between the two classes.

  9. The following user says thank you to ChrisW67 for this useful post:

    gboelter (8th November 2009)

  10. #7
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: Why my setter don't work?

    Chris,

    what else can I say then THANK YOU, THANK YOU, THANK YOU ....

    I was fighting with that for almost 2 days and I don't like to know how many days more without your help.

    Thanks again.

    Guenther
    Davao City, Philippines, Planet Earth, 29.0 °C

  11. #8
    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: Why my setter don't work?

    You're welcome,

    Chris
    Brisbane, Australia, Planet Earth, 25°C... beautiful one day, perfect the next

Similar Threads

  1. Making MySQL plugin work on a windows x86 enviroment
    By Baasie in forum Installation and Deployment
    Replies: 1
    Last Post: 2nd September 2009, 15:15
  2. getting MySQL to work with Qt
    By Ashish in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2009, 08:57
  3. Qt4 : QPainter::setRedirected doesn't work
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2008, 17:52
  4. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  5. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20

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.