读书人

一个很小程序为啥Qt的信号与槽机制就

发布时间: 2012-12-16 12:02:32 作者: rapoo

一个小小的程序,为啥Qt的信号与槽机制就不能用?
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
class QPushButton;

class MainWindow: public QMainWindow
{
private:
QPushButton *button;

public:
MainWindow();

private slots:
void Button();
};

#endif // MAINWINDOW_H


//mainwindow.cpp
#include <mainwindow.h>

#include <Qtgui>

MainWindow::MainWindow()
{
button = new QPushButton(tr("Call exe"), this);
QObject::connect(button, SIGNAL(clicked()),
this, SLOT(Button()));
}

void MainWindow::Button()
{
QMessageBox::about(this, tr("asdf"),
tr("asdf"));
}

//main.cpp
#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow *mainWin = new MainWindow();
mainWin->show();

return app.exec();
}


因为一些原因,有一段时间没用Qt了,今天想写个程序测试下一个东西,
居然怎么不行,其中connect()米起作用 我不知道哪里错了,
希望前辈们帮我这个菜鸟看下 非常感谢!

还有一个小问题: 我使用QProcess来调用外部的一个程序 利用绝对路径可以,但是相对路径不行,
是我用错了吗?

QProcess *myProcess = new QProcess();
myProcess->start(":/images/test2.exe"); //这个不行
//myProcess->start("E:\\test\\Debug\\test.exe"); //这个可以


在此非常感谢
[解决办法]
难道是没加Q_OBJECT原因。。

读书人网 >QT开发

热点推荐