0
我正在使用QListView
来显示MySQL数据库中名称的一个简单列表,现在我需要将所选值发送到下一个窗口当点击时Next>按钮,我是Qt新手,看到了大约QAbstractListModel
类,但是我没有得到哪一个使用和如何,引导我,预先感谢你。从QListView中选择值并提交,将它传递给下一个窗口?
我正在使用QListView
来显示MySQL数据库中名称的一个简单列表,现在我需要将所选值发送到下一个窗口当点击时Next>按钮,我是Qt新手,看到了大约QAbstractListModel
类,但是我没有得到哪一个使用和如何,引导我,预先感谢你。从QListView中选择值并提交,将它传递给下一个窗口?
一些对你的伪代码...
mainwindow.h
class MainWindow : public QMainWindow
{
...
signals:
void sendListText(const QString&);
private slots:
void nextClicked(void);
...
};
mainwindow.cpp
MainWindow::MainWindow(QWidget* parent)
{
ui.setupUi(this);
connect(ui.nextButton, SIGNAL(clicked()), this, SLOT(nextClicked()));
}
MainWindow::nextClicked(void)
{
QModelIndex current = ui.list->currentIndex();
qDebug() << current.data().toString();
emit(sendListText(current.data().toString());
}
otherwindow.h
class OtherWindow
{
...
public slots:
void setEditText(const QString&);
};
otherwindow.cpp
void OtherWindow::setEditText(const QString& text)
{
// add your text
}
现在你必须在MainWindow::sendListText()
连接插槽OtherWindow::setEditText()
,你可以访问他们两个。
洙长哉
嗨Zaiborg,非常感谢,u能PLZ使其在代码的方式... – highlander141 2013-02-18 04:54:50
编辑答案。现在你必须用它填充你的新窗口(或者另一个小部件)。 – Zaiborg 2013-02-18 07:02:42
对,我在编译窗口中得到了字符串,我需要将它传递给另一个窗口并在QTextEdit中显示它。所以Next按钮的信号必须调用QTextEdit的插槽?与此类似。?引导我感谢.. – highlander141 2013-02-18 08:12:40