I am using QListView
to display a simple list of Names from MySQL Database, now I need to send selected value to the Next Window when clicked on Next > button, I am new to Qt, saw about QAbstractListModel
class, but I am not getting which one to use and how, Guide me, thank you in advance.
some pseudo code for you...
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
}
now you have to connect the MainWindow::sendListText()
to the slot OtherWindow::setEditText()
where you have access to both of them.
soo long zai