Results 1 to 18 of 18

Thread: custom slot/signal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: custom slot/signal

    Quote Originally Posted by awnjoor
    why i have to move the moc directive down
    Because main.moc contains implementation of myWidget methods (which were added by Q_OBJECT macro) and in C++ you have to place method implementation after corresponding class definition.

  2. #2
    Join Date
    Jul 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom slot/signal

    sigh, im trying to do the custom slot/signal again but it is not working. here is the code

    Qt Code:
    1. #include<QTableWidgetItem>
    2. #include<QApplication>
    3. #include<QWidget>
    4. #include<QPushButton>
    5. #include<QLabel>
    6. #include<QFont>
    7. #include<QLineEdit>
    8. #include<QTableWidget>
    9. #include<QVBoxLayout>
    10. #include<QHBoxLayout>
    11. #include<QStringList>
    12. #include<QtSql/QSqlDatabase>
    13. #include<QtSql/QSqlQuery>
    14. #include<QString>
    15. #include<QObject>
    16.  
    17. class myWidget:public QWidget{
    18. Q_OBJECT
    19.  
    20. public:
    21. myWidget(QWidget *parent=0);
    22.  
    23. private slots:
    24. void processInput();
    25.  
    26. private:
    27. QLabel *displayItem;
    28. QLineEdit *itemnumber;
    29. };
    30.  
    31. myWidget::myWidget(QWidget *parent)
    32. :QWidget(parent)
    33. {
    34. setWindowState(Qt::WindowFullScreen);
    35.  
    36. QLabel *title = new QLabel;
    37. title->setFont(QFont("Verdana", 30, 0));
    38. title->setText("title");
    39. title->setAlignment(Qt::AlignHCenter);
    40.  
    41. QLabel *item=new QLabel;
    42. item->setFont(QFont("verdana", 15, QFont::Bold));
    43. item->setText("Item");
    44.  
    45. displayItem=new QLabel;
    46. //displayItem->setFont(QFont("verdana", 15, QFont::Bold));
    47. //displayItem->setText("asdf");
    48.  
    49. itemnumber=new QLineEdit;
    50. itemnumber->setMaxLength(10);
    51.  
    52. QLabel *quantity=new QLabel;
    53. quantity->setFont(QFont("verdana", 15, QFont::Bold));
    54. quantity->setText("Quantity");
    55.  
    56. QLineEdit *quantitynumber=new QLineEdit;
    57. quantitynumber->setMaxLength(10);
    58.  
    59. QStringList columnLabels;
    60. columnLabels << "Item" << "#" << "TOTAL";
    61.  
    62. QTableWidget *tableWidget=new QTableWidget;
    63. tableWidget->setRowCount(1);
    64. tableWidget->setColumnCount(3);
    65. tableWidget->setHorizontalHeaderLabels(columnLabels);
    66. tableWidget->setColumnWidth(0, 250);
    67. tableWidget->setColumnWidth(1, 30);
    68. tableWidget->setColumnWidth(2, 100);
    69.  
    70. QHBoxLayout *hLeft1=new QHBoxLayout;
    71. hLeft1->addWidget(item);
    72. hLeft1->addWidget(itemnumber);
    73.  
    74. QHBoxLayout *hLeft2=new QHBoxLayout;
    75. hLeft1->addWidget(quantity);
    76. hLeft1->addWidget(quantitynumber);
    77.  
    78. vLeft->addLayout(hLeft1);
    79. vLeft->addLayout(hLeft2);
    80.  
    81. hLeft->addLayout(vLeft);
    82. hLeft->addStretch(0);
    83.  
    84. QVBoxLayout *mainLeft=new QVBoxLayout;
    85. mainLeft->addWidget(displayItem);
    86. mainLeft->addStretch(0);
    87. mainLeft->addLayout(hLeft);
    88. mainLeft->addStretch(0);
    89.  
    90. QHBoxLayout *mainBottom=new QHBoxLayout;
    91. mainBottom->addLayout(mainLeft);
    92. mainBottom->addWidget(tableWidget);
    93.  
    94. QVBoxLayout *mainLayout=new QVBoxLayout(this);
    95. mainLayout->addWidget(title);
    96. mainLayout->addSpacing(80);
    97. mainLayout->addLayout(mainBottom);
    98. setLayout(mainLayout);
    99.  
    100. itemnumber->setFocus();
    101. //itemnumber->setText("asdf");
    102.  
    103. connect(itemnumber, SIGNAL(returnPressed()), this, SIGNAL(processInput()));
    104.  
    105. }
    106.  
    107. void myWidget::processInput(){
    108. //QString text=itemnumber->text();
    109. itemnumber->setText("asfd");
    110. }
    111.  
    112. int main(int argc, char *argv[]){
    113. QApplication app(argc, argv);
    114. myWidget window;
    115.  
    116. window.show();
    117. return app.exec();
    118. }
    119.  
    120. #include "client.moc"
    To copy to clipboard, switch view to plain text mode 

    everything compiles fine, it just doesnt do the processInput() when i press enter in itemnumber lineedit.

    EDIT:
    it seems that item number is not emitting the returnPressed() signal because i tried replacing it with

    Qt Code:
    1. connect(itemnumber, SIGNAL(returnPressed()), qApp, SIGNAL(quit()));
    To copy to clipboard, switch view to plain text mode 

    and when i pressed enter nothing happened.
    Last edited by awnjoor; 17th July 2006 at 05:07.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: custom slot/signal

    The latter should be SLOT:
    connect(itemnumber, SIGNAL(returnPressed()), this, SLOT(processInput()));
    J-P Nurmi

  4. #4
    Join Date
    Jul 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom slot/signal

    and i wonder how did i miss that one ..

    thank you

Similar Threads

  1. Custom plugin for a layout
    By cocheci in forum Qt Tools
    Replies: 2
    Last Post: 12th June 2006, 18:36
  2. Replies: 5
    Last Post: 16th May 2006, 20:38
  3. Custom Qt dll name
    By tony007 in forum Installation and Deployment
    Replies: 2
    Last Post: 10th March 2006, 15:29
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Replies: 4
    Last Post: 1st March 2006, 23:11

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.