Results 1 to 2 of 2

Thread: append slots not... appending?

  1. #1
    Join Date
    May 2006
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question append slots not... appending?

    I'm new to Qt and have some bare (console) c++ experience, so I expect this is some small error of mine, but for the life of me, I can't figure it out.

    I can call myTextEdit->append() just fine in static code, but connecting a signal to it doesn't seem to work:

    Qt Code:
    1. #include <QApplication>
    2. #include <QObject>
    3. #include <QWidget>
    4. #include <QTextEdit>
    5. #include <QPushButton>
    6. #include <QVBoxLayout>
    7.  
    8. int main(int argc, char *argv[]) {
    9.  
    10. QApplication app(argc, argv);
    11.  
    12. QWidget* window = new QWidget;
    13. QPushButton* aButton = new QPushButton("A Button");
    14. QTextEdit* aTextEdit = new QTextEdit();
    15. QTextDocument* aDocument = new QTextDocument("Text");
    16.  
    17. aButton->setFont(QFont("Impact", 18, QFont::Bold));
    18. aButton->setGeometry(10, 40, 180, 40);
    19. aTextEdit->setDocument(aDocument);
    20. aTextEdit->append("\nSome more text");
    21.  
    22. QObject::connect(aButton, SIGNAL(clicked()), aTextEdit, SLOT(append("\nSome Dynamic Text")));
    23.  
    24. QVBoxLayout* layout = new QVBoxLayout;
    25. layout->addWidget(aTextEdit);
    26. layout->addWidget(aButton);
    27.  
    28. window->resize(300, 300);
    29. window->setLayout(layout);
    30. window->show();
    31.  
    32. return app.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 

    Other slots I connect to seem to work fine (Such as clear(), cut(), paste(), etc.) but append(), setPlainText(), etc... basically anything that would achieve what I want, doesn't do anything. I've tried these commands on the QDocument the QTextEdit contains as well-- both automatic and self-created. I've tried using QStrings and blocks of static test for the append() function (Both work fine in static code) and still no luck.

    I hate to think that this could be a result of my relative newness to c++, but the other slots work, so I don't think that's it...

    Appending QListWidgets seems to have the same problem, but I haven't done extensive testing.

  2. #2
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: append slots not... appending?

    Hi,you program doesn't work because the signal and the slot you are using doesn't have the same signature:
    The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)
    Moreover, I think that you can't also pass the variable as the argument of the slot (eg: "\n this is the text") because you have to specify only the TYPE of the variable (QString in this case) that you have to pass. In this case you could do something like his:
    Qt Code:
    1. connedt(abutton,SIGNAL(clicked()),textedit,SLOT(write()));
    2. void TextEdit::wrtite(){ append("This is the text");}
    To copy to clipboard, switch view to plain text mode 

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

    Slip Nine (26th May 2006)

Similar Threads

  1. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28
  2. Unused parameters in slots
    By ePharaoh in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2006, 08:30
  3. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 22:09
  4. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 08:51
  5. Missing slots
    By Mariane in forum Newbie
    Replies: 1
    Last Post: 5th February 2006, 01:50

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.