2013-02-16 45 views

回答

1

一些对你的伪代码...

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(),你可以访问他们两个。

洙长哉​​

+0

嗨Zaiborg,非常感谢,u能PLZ使其在代码的方式... – highlander141 2013-02-18 04:54:50

+0

编辑答案。现在你必须用它填充你的新窗口(或者另一个小部件)。 – Zaiborg 2013-02-18 07:02:42

+0

对,我在编译窗口中得到了字符串,我需要将它传递给另一个窗口并在QTextEdit中显示它。所以Next按钮的信号必须调用QTextEdit的插槽?与此类似。?引导我感谢.. – highlander141 2013-02-18 08:12:40

相关问题