Qt4 在使用信号和;Qt中的插槽将出现错误

Qt4 在使用信号和;Qt中的插槽将出现错误,qt4,Qt4,错误是:错误:没有匹配的函数用于调用“QObject::connect(MainWindow*,const char*,MainWindow*,const char*)” 在second()成员函数中,插槽进度()与定义不匹配。 那么谁能解决这个问题呢 #include <QtCore/QCoreApplication> #include<QFuture> #include<QtConcurrentMap> #include<QtCore> #in

错误是:
错误:没有匹配的函数用于调用“QObject::connect(MainWindow*,const char*,MainWindow*,const char*)”
在second()成员函数中,插槽进度()与定义不匹配。

那么谁能解决这个问题呢

#include <QtCore/QCoreApplication>
#include<QFuture>
#include<QtConcurrentMap>
#include<QtCore>
#include<QString>
int i =0;

namespace Ui {
    class MainWindow;
}

class MainWindow
{
  Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:
    void finished();

public slots:
    void progress(const QString& status);

public:
    void search();
    void second();

};

void MainWindow::progress(const QString& status)
{
    printf("progress bar %d is finished", i);
    i++;
}
void MainWindow::search()
{
    QFuture<void> future=QtConcurrent::run(this,&MainWindow::second);
}
void MainWindow::finished()
{
    printf("signal got finished");
}

void MainWindow::second()
{
    MainWindow n,o;
    QObject::connect(&n,SIGNAL(finished()),&o,
                     SLOT(progress(const QString&)));
    o.progress("hello");
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MainWindow mi;
    mi.search();
    return a.exec();
}
#包括
#包括
#包括
#包括
#包括
int i=0;
名称空间用户界面{
类主窗口;
}
类主窗口
{
Q_对象
公众:
显式主窗口(QWidget*parent=0);
~main窗口();
信号:
无效完成();
公众时段:
无效进度(常量字符串和状态);
公众:
无效搜索();
void second();
};
void主窗口::进度(常量字符串和状态)
{
printf(“进度条%d已完成”,i);
i++;
}
void主窗口::搜索()
{
QFuture future=QtConcurrent::run(this,&MainWindow::second);
}
void MainWindow::finished()
{
printf(“信号完成”);
}
void MainWindow::second()
{
主窗口n,o;
QObject::连接(&n),信号(完成(),&o,
时隙(进程(常量QString&));
o、 进展(“你好”);
}
int main(int argc,char*argv[])
{
qcorea应用程序(argc、argv);
主窗口mi;
mi.search();
返回a.exec();
}

您没有从QObject交付的类继承。因为您的主窗口必须是QMainWindow交付的类

首先,您的类必须(不一定直接)继承自
QObject
类(请参见)。
此外,在
main()
中,您应该
show()
您的小部件
另外,您的
connect()
调用在运行时也会失败,因为
Q_信号
Q_插槽
必须具有相同的参数集。如果需要区分信号(添加附加参数),请考虑使用<代码> QSaleMalPer-< /Cord>类。看