QComboBox信号槽的问题

C_arm 2011-08-21 04:06:45
从网上下载了一个小程序测试QComboBox的信号槽

#include <QApplication>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
#include <QString>
void print2Screen(){
printf("changed\n");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win =new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
QComboBox *combo = new QComboBox();
QLabel *label = new QLabel("hello");
QPushButton *helloButton = new QPushButton("Show Label");
combo->addItem("A");
combo->addItem("B");
combo->addItem("C");
QObject::connect(combo, SIGNAL(activated(int)),label, SLOT(hide()));
QObject::connect(combo, SIGNAL(currentIndexChanged(int)),label, SLOT(print2Screen()));
QObject::connect(helloButton, SIGNAL(clicked()),label, SLOT(show()));
layout->addWidget(label);
layout->addWidget(combo);
layout->addWidget(helloButton);

win->setLayout(layout);
win->showMaximized();
return app.exec();
}

运行时报错:QObject::connect: No such slot QLabel::print2Screen()

哪位帮忙看看什么问题?
谢谢!
...全文
1145 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yesulan 2013-12-19
  • 打赏
  • 举报
回复
print2Screen(int) 应带一个参数
i丹明扬 2013-03-04
  • 打赏
  • 举报
回复
#include <QApplication> #include <QLabel> #include <QPushButton> #include <QDateTime> #include <QString> #include <QTimer> #include <QObject> #include <sys/types.h> #include <unistd.h> #include <cstdio> #include <cstdlib> void getSysTime(); QString timeStr = NULL; void getSysTime(){ QDateTime time; timeStr = time.currentDateTime().toString("yyyy") + "年 " + \ time.currentDateTime().toString("M") + "月 " + \ time.currentDateTime().toString("d") + "日 " + \ time.currentDateTime().toString("h") + "点 " + \ time.currentDateTime().toString("m") + "分 " + \ time.currentDateTime().toString("s") + "秒"; printf("aaaaaaaaaaaaaaaaaaaaaaaaaaa"); // return timeStr; } int main(int argc,char *argv[]) { /*Process PID*/ pid_t pid; pid = fork(); //建孩子进程1,first child process if(pid == 0) //pid = 0, so it is child process { pid = fork(); if(pid > 0) //pid>0为second child procss的父进程 first child process { sleep(1); printf("the second process creat now\n"); exit(0); } sleep(2); printf("the third process creat now\n"); }else if(pid > 0) //father process { printf("the first process creat now\n"); QApplication app(argc,argv); QLabel *timeLabel = new QLabel("Time Show!!!"); timeLabel->resize(400,400); QTimer *timer =new QTimer(&app); QObject::connect(timer,SIGNAL(timeout()),&app,SLOT(getSysTime())); timer->start(1); timeLabel->setText(timeStr+"aaa"); timeLabel->show(); app.exec(); }else { printf("fork fail\n"); exit(-1); } exit(0); } 为什么我定义了还是不行呢???
trafficzxz 2011-11-10
  • 打赏
  • 举报
回复
没有定义,自然就没有了!
钱国正 2011-09-29
  • 打赏
  • 举报
回复
晕,你这个问题。。。
C_arm 2011-08-21
  • 打赏
  • 举报
回复
多谢1楼
canmeng 2011-08-21
  • 打赏
  • 举报
回复
你在类中没用定义这个slot函数。

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧