如您所见(如果您查看我以前的几个问题)我对 Qt 很陌生。我正在制作“read-from-excel-file-push-to-some-DB”模块。
我想获得按钮返回的路径 main.cpp
所以,长话短说,这是我的代码:
fb_test.h
#ifndef FB_TEST_H
#define FB_TEST_H
#include <QtGui/QMainWindow>
#include "ui_fb_test.h"
class FB_test : public QMainWindow
{
Q_OBJECT
public:
FB_test(QWidget *parent = 0, Qt::WFlags flags = 0);
~FB_test();
private:
Ui::FB_testClass ui;
public slots:
QString on_pushButton_clicked();
};
#endif // FB_TEST_H
fb_test.cpp
#include <QtGui>
#include "fb_test.h"
FB_test::FB_test(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}
FB_test::~FB_test()
{
}
QString FB_test::on_pushButton_clicked()
{
QString path;
path = QFileDialog::getOpenFileName(
this,
"Choose a file to open",
QString::null,
QString::null);
return path;
}
主文件
#include <QApplication>
#include <QtGui>
#include <QtSql>
#include <QAxObject>
#include <QAxWidget>
#include "fb_test.h"
bool initExcel(QAxObject* &excelApp);
void getTableHeaders(QAxObject* _worksheet, QAxObject* _excel);
bool readExcelFile(QAxObject* excel, QString& file_path, QString& selected_list);
void getTableHeaders(QAxObject* _worksheet, QAxObject* _excel);
//....
//here's methods above implementation
//....
void excelTest(){
QAxObject* excel;
QString path = QString("C:\\databases\\oilnstuff.xls");//gonna use GUI choose
QString list = QString("list1");
if(initExcel(excel)){
if (readExcelFile(excel, path, list)){
//
}else{
//error output
}
}
excel->dynamicCall("Quit");
delete excel;
}
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QComboBox myCombo;
FB_test *test = new FB_test;
test->show();
excelTest();
return app.exec();
}
所以在这里,而不是这样的正确部分
QString path = QString("C:\\databases\\oilnstuff.xls");
我想得到什么QString FB_test::on_pushButton_clicked()
回报。
怎么做这样的东西?
UPD:好吧,这种方式行不通
QString mypath = test->ui.pushButton();
附言
哦,顺便说一句,我不确定我设计这个模块的方式。也许我应该把所有工作的东西移到main.cpp
那里并FB_test.cpp
得到什么按钮返回那里并且只调用?show()
main.cpp