Results 1 to 2 of 2

Thread: signal & slot problem

  1. #1
    Join Date
    Mar 2011
    Posts
    23
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default signal & slot problem

    i created one pushbutton and label in myClass.cpp;

    Qt Code:
    1. QLabel *lbl=new QLabel();
    2. QPushButton *btn=new QPushButton("button");
    3.  
    4. ui->tableWidget->setCellWidget(0,0,lbl);
    5. ui->tableWidget->setCellWidget(0,1,btn);
    To copy to clipboard, switch view to plain text mode 

    i want that: when i click button, calendar will open and when i click calendar, date will be written on label.
    and i want to use signal & slot.

    i created these functions:

    Qt Code:
    1. myClass.h
    2.  
    3. public:
    4.  
    5. public slots:
    6. void writeDate(QLabel *);
    7. void func();
    8. void openCal();
    9.  
    10. signals:
    11. void calClicked(QLabel *);
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. myClass.cpp
    2.  
    3. connect(btn,SIGNAL(clicked()),this,SLOT(openCal())); //it works
    4. connect(cal,SIGNAL(clicked(QDate)),this,SLOT(func()));//it works
    5. myClass *a,*b;
    6. QObject::connect(a, SIGNAL(calClicked(lbl)), b, SLOT(writeDate(lbl)));//it never works
    7.  
    8. void myClass::func()
    9. {
    10. emit calClicked(lbl);
    11. }
    12.  
    13. void myClass::writeDate(QLabel *lbl)
    14. {
    15. cal->close();
    16. lbl->setText(cal->selectedDate());
    17. }
    To copy to clipboard, switch view to plain text mode 

    but i always get error:QObject::connect: Cannot connect (null)::calClicked(lbl) to (null)::writeDate(lbl)


    sorry for my english.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: signal & slot problem

    Make sure that a and b pointers are initialized?

    //I don't really follow why you need two objects of that class? Shouldn't the functionality you talk about happen inside the object? Anyway this might be me - because i don't see the whole application code, so just check the pointers if i'm wrong with this part.

    LE: also the connect syntax is incorrect, if should be QLabel* instead of lbl. //you pass lbl when you emit the signal - at the connect you say only the parameter type.

Similar Threads

  1. Replies: 2
    Last Post: 3rd May 2011, 20:22
  2. SIGNAL and SLOT Problem
    By RHMK in forum Qt Programming
    Replies: 5
    Last Post: 26th December 2010, 12:45
  3. Signal and Slot Problem
    By waynew in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2010, 10:49
  4. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 18:10
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59

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.