2013年07月15日

先构建一份ui:
2013年07月15日

自动生成文件1:moc_gotocelldialog.cpp

#include "../gotocelldialog.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'gotocelldialog.h' doesn't include ."
#elif Q_MOC_OUTPUT_REVISION != 63
#error "This file was generated using the moc from 4.8.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_GoToCellDialog[] = {

  // content:
        6,       // revision
        0,       // classname
        0,     0, // classinfo
        1,   14, // methods
        0,     0, // properties
        0,     0, // enums/sets
        0,     0, // constructors
        0,       // flags
        0,       // signalCount

  // slots: signature, parameters, type, tag, flags
      16,   15,   15,   15, 0x08,

        0         // eod
};

static const char qt_meta_stringdata_GoToCellDialog[] = {
    "GoToCellDialog\0\0on_lineEdit_textChanged()\0"
};

void GoToCellDialog::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
    if (_c == QMetaObject::InvokeMetaMethod) {
        Q_ASSERT(staticMetaObject.cast(_o));
        GoToCellDialog *_t = static_cast(_o);
        switch (_id) {
        case 0: _t->on_lineEdit_textChanged(); break;
        default: ;
        }
    }
    Q_UNUSED(_a);
}

const QMetaObjectExtraData GoToCellDialog::staticMetaObjectExtraDat a = {
    0,   qt_static_metacall 
};

const QMetaObject GoToCellDialog::staticMetaObject = {
    { &QDialog::staticMetaObject, qt_meta_stringdata_GoToCellDialog,
      qt_meta_data_GoToCellDialog, &staticMetaObjectExtraDat a }
};

#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &GoToCellDialog::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION

const QMetaObject *GoToCellDialog::metaObject() const
{
    return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}

void *GoToCellDialog::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_GoToCellDialog))
        return static_cast(const_cast< GoToCellDialog*>(this));
    if (!strcmp(_clname, "Ui::GoToCellDialog"))
        return static_cast< Ui::GoToCellDialog*>(const_cast< GoToCellDialog*>(this));
    return QDialog::qt_metacast(_clname);
}

int GoToCellDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 1)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 1;
    }
    return _id;
}
QT_END_MOC_NAMESPACE


文件2:

#ifndef UI_GOTOCELLDIALOG_H
#define UI_GOTOCELLDIALOG_H

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

QT_BEGIN_NAMESPACE

class Ui_GoToCellDialog
{
public:
    QVBoxLayout *verticalLayout;
    QHBoxLayout *horizontalLayout;
    QLabel *label;
    QLineEdit *lineEdit;
    QHBoxLayout *horizontalLayout_2;
    QSpacerItem *horizontalSpacer;
    QPushButton *okButton;
    QPushButton *cancelButton;

    void setupUi(QDialog *GoToCellDialog)
    {
        if (GoToCellDialog->objectName().isEmpty())
            GoToCellDialog->setObjectName(QString::fromUtf8("GoToCellDialog"));
        GoToCellDialog->resize(249, 71);
        verticalLayout = new QVBoxLayout(GoToCellDialog);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        horizontalLayout = new QHBoxLayout();
        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
        label = new QLabel(GoToCellDialog);
        label->setObjectName(QString::fromUtf8("label"));

        horizontalLayout->addWidget(label);

        lineEdit = new QLineEdit(GoToCellDialog);
        lineEdit->setObjectName(QString::fromUtf8("lineEdit"));

        horizontalLayout->addWidget(lineEdit);


        verticalLayout->addLayout(horizontalLayout);

        horizontalLayout_2 = new QHBoxLayout();
        horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
        horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_2->addItem(horizontalSpacer);

        okButton = new QPushButton(GoToCellDialog);
        okButton->setObjectName(QString::fromUtf8("okButton"));
        okButton->setEnabled(false);
        okButton->setDefault(true);

        horizontalLayout_2->addWidget(okButton);

        cancelButton = new QPushButton(GoToCellDialog);
        cancelButton->setObjectName(QString::fromUtf8("cancelButton"));

        horizontalLayout_2->addWidget(cancelButton);


        verticalLayout->addLayout(horizontalLayout_2);


        retranslateUi(GoToCellDialog);

        QMetaObject::connectSlotsByName(GoToCellDialog);
    } // setupUi

    void retranslateUi(QDialog *GoToCellDialog)
    {
        GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "Dialog", 0, QApplication::UnicodeUTF8));
        label->setText(QApplication::translate("GoToCellDialog", "

Cell Location:

", 0, QApplication::UnicodeUTF8));
        okButton->setText(QApplication::translate("GoToCellDialog", "OK", 0, QApplication::UnicodeUTF8));
        cancelButton->setText(QApplication::translate("GoToCellDialog", "Cancel", 0, QApplication::UnicodeUTF8));
    } // retranslateUi

};

namespace Ui {
    class GoToCellDialog: public Ui_GoToCellDialog {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_GOTOCELLDIALOG_H

1、手动完成UI的建立,然后在cmd 中用qmake -project 命令,生成gotocell.rpo(父目录即为工程名),再用make gotocell.pro中生成工程。需要在VS中编辑文件时:再使用qmake -tp vc gotocell.pro即可。上面的两份代码均为自动生成的

2、gotocelldialog.h
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H

#include

#include "ui_gotocelldialog.h"

class GoToCellDialog:public QDialog,public Ui::GoToCellDialog
{
Q_OBJECT

public:
GoToCellDialog(QWidget *parent = 0);

private slots:
void on_lineEdit_textChanged();
};

#endif

3、gotocelldialog.cpp
#include

#include "gotocelldialog.h"

GoToCellDialog::GoToCellDialog(QWidget *parent)
:QDialog(parent)
{
setupUi(this);

QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));

connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));

}

void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}


3、main函数:

#include
#include

#include "gotocelldialog.h"

int main(int argc,char *argv[])
{
QApplication app(argc,argv);
GoToCellDialog *dialog = new GoToCellDialog;
dialog->show();
return app.exec();
}

如果是用vs编辑工程的话,每次加入消息传递就是信号槽等处理,都得重新用cmd重新生成工程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值