当前位置: 代码迷 >> QT开发 >> QT地址薄的有关问题
  详细解决方案

QT地址薄的有关问题

热度:64   发布时间:2016-04-25 04:21:06.0
QT地址薄的问题
在构造器中是这样:
    saveButton = new QPushButton(tr("Save..."));
    saveButton->setEnabled(true);
    saveButton->setToolTip(tr("Save contacts to a file."));

    connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));


void AddressBook::saveToFile()
{
    QString fileName = QFileDialog::getSaveFileName(this,
                                  tr("Save Address Book"), "",
                                  tr("Address Book (*.abk);;All Files(*)"));
    if(fileName.isEmpty())
    {
        return;
    }
    else
    {
        QFile file(fileName);

        if(!file.open(QIODevice::WriteOnly))
        {
            QMessageBox::information(this, tr("Unable to open file"),
                                     file.errorString());
            return;
        }

        QDataStream out(&file);
        out.setVersion(QDataStream::Qt_4_7);
        out<<contacts;
    }
}

点击saveButton按钮根本就没任何反应,
为什么实现不了呢?因为刚学QT,所以不熟悉,麻烦大师帮帮忙啊!!告诉小弟是哪里出错了吗?
------最佳解决方案--------------------
Q_OBJECT
public:
    构造函数();
public slots:  //1
    void saveToFile();
privite slots:  //2
    void saveToFile();

要向上面的1或者2那样声明,才可以作为槽函数使用,Q_OBJECT宏也是必须的,这个类必须继承自QObject。
这些条件全部都要具备。
------其他解决方案--------------------
引用:
Q_OBJECT
public:
    构造函数();
public slots:  //1
    void saveToFile();
privite slots:  //2
    void saveToFile();

要向上面的1或者2那样声明,才可以作为槽函数使用,Q_OBJECT宏也是必须的,这个类必须继承自QObject。
这些条件全部都要具备。

谢谢,我忘了,我把它放在了public:里面了,真的太感谢了!!
  相关解决方案