Results 1 to 5 of 5

Thread: Connection not properly done.... lineEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Connection not properly done.... lineEdit

    Hi:

    I'm new in this forum... trying to test QT. My background comes from MS Visual Studio.

    So, I'm having some troubles figuring out this connection (signal, slot) thing... I'm more used to the onLoad, onClose, etc... of MS

    The problem is silly. Very silly indeed.

    I'm using designer. A simple main window with a slider and a spin connected.

    I have a lineEdit where I want to display whatever I want depending on the value of the slider... not just the value of the slider... maybe some text saying something...

    So, It seems that I have to create a new connection... which it is not working as I expected... well, it's not working at all... I guess that maybe somebody here could have a look at the code and in 2 seconds see the error... it would help me to understand how this system works. Overall it looks really nice, but I don't see 100% clear the Event handling...

    Thanks!!!
    Regards,
    Hipogrito

    GTMain.h
    Qt Code:
    1. #ifndef GTMAIN_H
    2. #define GTMAIN_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. #include "ui_GTerm.h"
    7.  
    8. class GTMain : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. GTMain(QWidget *parent=0);
    14.  
    15. private:
    16. Ui::GTerm ui;
    17.  
    18. private slots:
    19. void updateText();
    20. };
    21.  
    22. #endif
    To copy to clipboard, switch view to plain text mode 



    GTMain.c
    Qt Code:
    1. #include "GTMain.h"
    2. #include "ui_GTerm.h"
    3.  
    4. GTMain::GTMain(QWidget *parent)
    5. : QMainWindow(parent)
    6. {
    7. // init the ui
    8. ui.setupUi(this);
    9. connect(ui.verticalSlider, SIGNAL(sliderMoved(int)), ui.lineEdit, SLOT(updateText()));
    10.  
    11. }
    12.  
    13.  
    14. void GTMain::updateText()
    15. {
    16. ui.lineEdit->clear();
    17. ui.lineEdit->setText("Modifing...");
    18. ui.lineEdit->show();
    19.  
    20. // Whatever... I just want to clear the line and show the new text...
    21. // I don't care at the beginning what to show, but I just want to be able to add whatever here in this method
    22. }
    To copy to clipboard, switch view to plain text mode 


    Now the file coming from the Designer:
    ui_GTerm.h
    Qt Code:
    1. ********************************************************************************
    2. ** Form generated from reading ui file 'GTerm.ui'
    3. **
    4. ** Created: Mon Apr 2 15:01:26 2007
    5. ** by: Qt User Interface Compiler version 4.2.0
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling ui file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_GTERM_H
    11. #define UI_GTERM_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QComboBox>
    18. #include <QtGui/QGroupBox>
    19. #include <QtGui/QLineEdit>
    20. #include <QtGui/QMainWindow>
    21. #include <QtGui/QMenu>
    22. #include <QtGui/QMenuBar>
    23. #include <QtGui/QSlider>
    24. #include <QtGui/QSpinBox>
    25. #include <QtGui/QStatusBar>
    26. #include <QtGui/QWidget>
    27.  
    28. class Ui_GTerm
    29. {
    30. public:
    31. QAction *actionAbout;
    32. QAction *actionQuit;
    33. QWidget *centralwidget;
    34. QGroupBox *groupBox;
    35. QSpinBox *spinBox;
    36. QComboBox *comboBox;
    37. QSlider *verticalSlider;
    38. QLineEdit *lineEdit;
    39. QMenuBar *menubar;
    40. QMenu *menuHelp;
    41. QMenu *menuFile;
    42. QStatusBar *statusbar;
    43.  
    44. void setupUi(QMainWindow *GTerm)
    45. {
    46. GTerm->setObjectName(QString::fromUtf8("GTerm"));
    47. actionAbout = new QAction(GTerm);
    48. actionAbout->setObjectName(QString::fromUtf8("actionAbout"));
    49. actionQuit = new QAction(GTerm);
    50. actionQuit->setObjectName(QString::fromUtf8("actionQuit"));
    51. centralwidget = new QWidget(GTerm);
    52. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    53. groupBox = new QGroupBox(centralwidget);
    54. groupBox->setObjectName(QString::fromUtf8("groupBox"));
    55. groupBox->setGeometry(QRect(30, 10, 131, 271));
    56. spinBox = new QSpinBox(groupBox);
    57. spinBox->setObjectName(QString::fromUtf8("spinBox"));
    58. spinBox->setGeometry(QRect(50, 90, 55, 29));
    59. comboBox = new QComboBox(groupBox);
    60. comboBox->setObjectName(QString::fromUtf8("comboBox"));
    61. comboBox->setGeometry(QRect(10, 30, 101, 26));
    62. verticalSlider = new QSlider(groupBox);
    63. verticalSlider->setObjectName(QString::fromUtf8("verticalSlider"));
    64. verticalSlider->setGeometry(QRect(20, 90, 16, 160));
    65. verticalSlider->setOrientation(Qt::Vertical);
    66. lineEdit = new QLineEdit(centralwidget);
    67. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    68. lineEdit->setGeometry(QRect(90, 400, 421, 29));
    69. GTerm->setCentralWidget(centralwidget);
    70. menubar = new QMenuBar(GTerm);
    71. menubar->setObjectName(QString::fromUtf8("menubar"));
    72. menubar->setGeometry(QRect(0, 0, 633, 25));
    73. menuHelp = new QMenu(menubar);
    74. menuHelp->setObjectName(QString::fromUtf8("menuHelp"));
    75. menuFile = new QMenu(menubar);
    76. menuFile->setObjectName(QString::fromUtf8("menuFile"));
    77. GTerm->setMenuBar(menubar);
    78. statusbar = new QStatusBar(GTerm);
    79. statusbar->setObjectName(QString::fromUtf8("statusbar"));
    80. GTerm->setStatusBar(statusbar);
    81.  
    82. menubar->addAction(menuFile->menuAction());
    83. menubar->addAction(menuHelp->menuAction());
    84. menuHelp->addAction(actionAbout);
    85. menuFile->addAction(actionQuit);
    86.  
    87. retranslateUi(GTerm);
    88.  
    89. QSize size(633, 633);
    90. size = size.expandedTo(GTerm->minimumSizeHint());
    91. GTerm->resize(size);
    92.  
    93. QObject::connect(verticalSlider, SIGNAL(sliderMoved(int)), spinBox, SLOT(setValue(int)));
    94. QObject::connect(spinBox, SIGNAL(valueChanged(int)), verticalSlider, SLOT(setValue(int)));
    95. QObject::connect(verticalSlider, SIGNAL(sliderMoved(int)), lineEdit, SLOT(update()));
    96.  
    97. QMetaObject::connectSlotsByName(GTerm);
    98. } // setupUi
    99.  
    100. void retranslateUi(QMainWindow *GTerm)
    101. {
    102. GTerm->setWindowTitle(QApplication::translate("GTerm", "GTERM v003", 0, QApplication::UnicodeUTF8));
    103. actionAbout->setText(QApplication::translate("GTerm", "About", 0, QApplication::UnicodeUTF8));
    104. actionQuit->setText(QApplication::translate("GTerm", "Quit", 0, QApplication::UnicodeUTF8));
    105. groupBox->setTitle(QApplication::translate("GTerm", "Control 1", 0, QApplication::UnicodeUTF8));
    106. comboBox->clear();
    107. comboBox->addItem(QApplication::translate("GTerm", "Element01", 0, QApplication::UnicodeUTF8));
    108. comboBox->addItem(QApplication::translate("GTerm", "Element02", 0, QApplication::UnicodeUTF8));
    109. comboBox->addItem(QApplication::translate("GTerm", "Element03", 0, QApplication::UnicodeUTF8));
    110. comboBox->addItem(QApplication::translate("GTerm", "Element04", 0, QApplication::UnicodeUTF8));
    111. menuHelp->setTitle(QApplication::translate("GTerm", "Help", 0, QApplication::UnicodeUTF8));
    112. menuFile->setTitle(QApplication::translate("GTerm", "File", 0, QApplication::UnicodeUTF8));
    113. } // retranslateUi
    114.  
    115. };
    116.  
    117. namespace Ui {
    118. class GTerm: public Ui_GTerm {};
    119. } // namespace Ui
    120.  
    121. #endif // UI_GTERM_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 2nd April 2007 at 21:41. Reason: missing [code] tags

Similar Threads

  1. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48
  2. Replies: 3
    Last Post: 22nd June 2006, 16:27
  3. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06
  4. Can I launch a dial-up connection in Windows?
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 9th February 2006, 12:32
  5. subclassing or redrawing a lineEdit
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 18: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.