Results 1 to 8 of 8

Thread: call variable from other function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: call variable from other function

    it's code for example:

    ui.h:
    Qt Code:
    1. #ifndef UI_GUI_H
    2. #define UI_GUI_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QLabel>
    9. #include <QtGui/QMainWindow>
    10. #include <QtGui/QMenuBar>
    11. #include <QtGui/QPushButton>
    12. #include <QtGui/QWidget>
    13.  
    14. class Ui_MainWindow
    15. {
    16. public:
    17. QWidget *centralwidget;
    18. QPushButton *pushButtonOpen;
    19. QPushButton *pushButtonClose;
    20. QLabel *label;
    21. QMenuBar *menubar;
    22.  
    23. void setupUi(QMainWindow *MainWindow)
    24. {
    25. .....
    26. label = new QLabel(centralwidget);
    27. label->setObjectName(QString::fromUtf8("label"));
    28. label->setGeometry(QRect(60, 100, 46, 14));
    29. .......
    30.  
    31. retranslateUi(MainWindow);
    32. //QObject::connect(pushButtonOpen, SIGNAL(clicked()), label, SLOT(clear()));
    33.  
    34. QMetaObject::connectSlotsByName(MainWindow);
    35. } // setupUi
    36.  
    37. void retranslateUi(QMainWindow *MainWindow)
    38. {
    39. ........
    40. label->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
    41. Q_UNUSED(MainWindow);
    42. } // retranslateUi
    43.  
    44. };
    45.  
    46. namespace Ui {
    47. class MainWindow: public Ui_MainWindow {};
    48. } // namespace Ui
    49.  
    50. #endif // UI_GUI_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3.  
    4. #include "ventana.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. intervalo = 0;
    11.  
    12. Ventana widget;
    13. widget.show();
    14.  
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    ventana.h:
    Qt Code:
    1. #include "ui.h"
    2.  
    3. class Ventana : public QMainWindow, private Ui::MainWindow
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. Ventana();
    9.  
    10. public slots:
    11. void Bopen();
    12. void Bclose();
    13. };
    To copy to clipboard, switch view to plain text mode 

    ventana.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include "ventana.h"
    3. #include "function.h"
    4.  
    5. Ventana::Ventana()
    6. {
    7. setupUi(this);
    8.  
    9. connect(pushButtonOpen, SIGNAL(clicked()), this, SLOT(Bopen()));
    10. connect(pushButtonClose, SIGNAL(clicked()), this, SLOT(Bclose()));
    11. }
    12.  
    13. void Ventana::Bclose(){
    14. label->setText(QString("CloseOk"));
    15. functionDoSomething();
    16. }
    17.  
    18. void Ventana::Bopen(){
    19. label->setText(QString("OpenOK"));
    20. }
    To copy to clipboard, switch view to plain text mode 

    From HERE im call label->setText();
    But say is undeclared.

    function.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include "function.h"
    3.  
    4. void functionDoSomething(){
    5. //here call to Qlabel
    6. label->setText(QString("HELLO WORLD"));
    7. }
    To copy to clipboard, switch view to plain text mode 

    function.h:
    Qt Code:
    1. void functionDoSomething();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: call variable from other function

    you cannot add any members there.
    Do it in designer, and uic will put them there.

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: call variable from other function

    Quote Originally Posted by marcel View Post
    you cannot add any members there.
    Do it in designer, and uic will put them there.

    Regards
    Im not understand!!

Similar Threads

  1. Cannot call function without object
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 11th June 2007, 14:55
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  4. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  5. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26

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.