Results 1 to 4 of 4

Thread: C++/Qt5.9.1 - Showing a ui form, passed variables not accessible!

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt5.9.1 - Showing a ui form, passed variables not accessible!

    Hello.

    Qt 5.9.1

    I'm showing a ui form and the passed variables come up as not accessible.
    I had it working for a while and for some reason, now it does not.
    I'm using some of Qt Creators built in slot mechanisms.
    Maybe I deleted something, I don't know.
    Anybody have an insiight?

    Regards
    Qt Code:
    1. //Debug output
    2. Locals
    3. activeLayer <not accessible> QString
    4. btnArea 0x4 QWidget*
    5. captionList <not accessible> QList<QString>
    6. layout 0x30 QLayout*
    7. parent 0x0 QWidget*
    8. this @0x27d1c050 qg_divideoptions
    9. Inspector
    10. Expressions
    11. Return Value
    12. Tooltip
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //Constructor
    2. //activeLayer and buttonCaptions have valid data
    3.  
    4. QDialog *myNewform = new qg_divideoptions( activeLayer, buttonCaptions );
    5.  
    6. myNewform->setWindowFlags( myNewform->windowFlags() & ~Qt::WindowContextHelpButtonHint );
    7. myNewform->setFixedSize(300, 400);
    8.  
    9. QObject::connect( myNewform,
    10. SIGNAL( dataToSend(const int&, //newticks
    11. const int&, //newsize
    12. const bool&, //hidedhow
    13. const bool&, //breaks
    14. const int&)), //newLayer
    15. this,
    16. SLOT( gotData(const int, //ticksR
    17. const int, //sizeR
    18. const bool, //showhideR
    19. const bool, //breaksR
    20. const int)) ); //layerR
    21.  
    22. myNewform->exec(); //*** modal ***
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //Form header
    2. #ifndef QG_DIVIDEOPTIONS_H
    3. #define QG_DIVIDEOPTIONS_H
    4.  
    5. #include <QDialog>
    6. #include <QRadioButton>
    7.  
    8. namespace Ui {
    9. class qg_divideoptions;
    10. }
    11.  
    12. class qg_divideoptions : public QDialog
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit qg_divideoptions( QString, QList<QString>, QWidget *parent = 0 );
    18. ~qg_divideoptions();
    19. Ui::qg_divideoptions *ui;
    20.  
    21. private:
    22. void closeEvent(QCloseEvent *event);
    23. int newticks, newsize, newLayer, qty;
    24. bool showhide, breaks;
    25.  
    26. signals:
    27. void dataToSend( const int& newticks,
    28. const int& newsize,
    29. const bool& showhide,
    30. const bool& breaks,
    31. const int& newLayer );
    32.  
    33. private slots:
    34. void on_buttonBox_accepted();
    35. void on_buttonBox_rejected();
    36. void on_Sp1_valueChanged( int );
    37. void on_Sp2_valueChanged( int );
    38. void on_showhide_pressed();
    39. void on_breaks_pressed();
    40. void slot_on_layer_btn_pressed();
    41. void slot_btn_lost_focus( bool );
    42. void delete_form_items();
    43. };
    44.  
    45. #endif // QG_DIVIDEOPTIONS_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //Form .cpp
    2. qg_divideoptions::qg_divideoptions( QString activeLayer,
    3. QList<QString> captionList,
    4. QWidget *parent ) :
    5. QDialog(parent),
    6. ui(new Ui::qg_divideoptions)
    7. {
    8. this->show(); // for debug
    9. qDebug() << "1" << captionList;
    10. qDebug() << "2" << activeLayer;
    11. qDebug() << "3" << ui->Sp1->value();
    12. qDebug() << "4" << ui->Sp2->value();
    13. newticks = ui->Sp1->value();
    14. newsize = ui->Sp2->value();
    15. qty = captionList.size();
    16. showhide = false;
    17. breaks = false;
    18.  
    19. QWidget* btnArea = new QWidget;
    20. btnArea->setObjectName( "btnArea" );
    21. btnArea->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
    22. btnArea->setLayout(new QVBoxLayout(btnArea));
    23. ui->scrollArea->setWidget(btnArea);
    24.  
    25. QLayout *layout = btnArea->layout();
    26. layout->setSpacing(0);
    27. for (int i = 0; i < qty; i++)
    28. {
    29. QRadioButton* btn = new QRadioButton( captionList.at(i) );
    30.  
    31. QObject::connect( btn, SIGNAL(toggled(bool)), this, SLOT(slot_btn_lost_focus(bool)) );
    32. QObject::connect( btn, SIGNAL( clicked(bool) ), this, SLOT( slot_on_layer_btn_pressed() ) );
    33.  
    34. btn->setObjectName( QString::number(i) );
    35. layout->addWidget( btn );
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    509
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt5.9.1 - Showing a ui form, passed variables not accessible!

    Hi, I am not sure if mixed declarations like in your signal and slot work (one uses references, the other does not).
    Do you get a line about problems with the connection in the output window when you debug your program?

    Ginsengelf

  3. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt5.9.1 - Showing a ui form, passed variables not accessible!

    Hello,

    Thanks for your reply.

    " I am not sure if mixed declarations like in your signal and slot work"

    I can only say that at one point the program was working, and the connections
    worked, that method was one I found on Google.
    I wonder if the problem is with the auto slot mechanism in Qt Designer,
    I see some notes on the intertnet about problems with this method,
    some people say don't use it.
    No debug warnings, the program crashes too soon.

    Regards

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: C++/Qt5.9.1 - Showing a ui form, passed variables not accessible!

    I wonder if the problem is with the auto slot mechanism in Qt Designer
    If you are writing explicit connect() statements in -your- code, then you aren't using Qt Designer's automatic connection mechanism. These come into play when you have a UI variable like "myButton" and you declare a slot in the class corresponding to the UI file like "on_myButton_clicked()". The MOC compiler will see this declaration, match it up to the corresponding UI variable, and make the connection for you.

    No debug warnings, the program crashes too soon.
    I suggest that the problem you are seeing has nothing to do with the UI file, connections, or anything else. If your program is crashing, then it is likely that you have either corrupted memory or the stack in some way and the crash is just the result. That the debugger can't access the values of your UI variables is a sure sign of this - the object you are trying to examine is corrupted or otherwise invalid, and the debugger can't resolve the values of the variables it contains.

    Fix the problem that causes the crash first. Look for uninitialized or NULL variables, out-of-bounds writing to arrays, etc. And change the slot arguments to match the signal, as Ginsengelf says. One uses pass by value (int), the other pass by reference (int &).

    Who cares if you found it on Google? Do you believe everything you read online? Let me tell you about my poor uncle who was assassinated in the coup and left me $25,000,000 but it is stuck in a bank back in his homeland. I could use your help getting it out, and I'll give you half of it as a reward...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt Creator 2.2.1 not showing variables on Mac
    By dave2k in forum Qt Tools
    Replies: 1
    Last Post: 22nd August 2011, 21:41
  2. accessible Clients
    By jörg in forum Qt Programming
    Replies: 7
    Last Post: 15th June 2011, 14:40
  3. How to call to variables of another form
    By matulik in forum Newbie
    Replies: 3
    Last Post: 14th May 2010, 18:32
  4. Showing form - help
    By waynew in forum Newbie
    Replies: 3
    Last Post: 28th October 2009, 01:04

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.