• 16075阅读
  • 12回复

QTableView 如何(1)选择一行(2)被选中后发送一个信号(3)捕捉信号 [复制链接]

上一主题 下一主题
离线liwenfu24
 
只看楼主 倒序阅读 楼主  发表于: 2010-02-26
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
我想写一个小程序 (由于初学Qt,用了一个星期还未搞定,希望多多指教)


表格(QTabaleView) 用于总揽所有records
文本(QTextEdit)   用于详细显示一个record

需要实现下列几步:

(1) [关键步骤]选择一行


(2) [关键步骤] 被选中后发送一个信号
当表格(QTabaleView)中的一行(row) 被选中时,发送一个信号

(3)[这步我可以自己完成] 捕捉信号,显示详细信息。
void MainWindow::updateDetailedView(int row)
{
     wordEditor->setPlainText(model->data(model->index(row, 0, QModelIndex()), Qt::DisplayRole).toString());
     meningEditor->setPlainText(model->data(model->index(row, 1, QModelIndex()), Qt::DisplayRole).toString());
     ratingEditor->setPlainText(model->data(model->index(row, 2, QModelIndex()), Qt::DisplayRole).toString());
        
}
[ 此帖被liwenfu24在2010-02-26 02:51重新编辑 ]
离线sun83819
只看该作者 1楼 发表于: 2010-02-26
我也是问的跟楼主相同的问题
离线hover_sky

只看该作者 2楼 发表于: 2010-02-26
emit  tableView->clicked(QModelIndex index);
离线xtfllbl

只看该作者 3楼 发表于: 2010-02-26
引用第2楼hover_sky于2010-02-26 09:10发表的  :
emit  tableView->clicked(QModelIndex index);

这个好。
上海欢迎您
离线sun83819
只看该作者 4楼 发表于: 2010-02-26
引用第2楼hover_sky于2010-02-26 09:10发表的  :
emit  tableView->clicked(QModelIndex index);


发送clicked 这个信号如何关联到
updateDetailedView呢
离线xtfllbl

只看该作者 5楼 发表于: 2010-02-26
引用第4楼sun83819于2010-02-26 09:19发表的  :
发送clicked 这个信号如何关联到
updateDetailedView呢

接收这个信号阿。写一句connect把他们联系起来。
上海欢迎您
离线sun83819
只看该作者 6楼 发表于: 2010-02-26
QObject::connect(ui.tableView, SIGNAL(clicked(QModelIndex )), this, SLOT(updateDetailedView()));

是这样吗?  我不加emit  tableView->clicked(QModelIndex index); 为什么不行?
非要加上 emit  tableView->clicked(QModelIndex index);句?
离线xtfllbl

只看该作者 7楼 发表于: 2010-02-26
引用第6楼sun83819于2010-02-26 11:20发表的  :
QObject::connect(ui.tableView, SIGNAL(clicked(QModelIndex )), this, SLOT(updateDetailedView()));
是这样吗?  我不加emit  tableView->clicked(QModelIndex index); 为什么不行?
非要加上 emit  tableView->clicked(QModelIndex index);句?

兄弟,你不发信号,何来接受信号,connect的用处只是把信号和槽链接起来,没有发信号的功能。
上海欢迎您
离线hover_sky

只看该作者 8楼 发表于: 2010-02-26
emit  tableView->clicked(QModelIndex index);

是用来发射信号的
离线sun83819
只看该作者 9楼 发表于: 2010-02-26
多谢2位,,我明白了点。。
那我的emit  tableView->clicked(QModelIndex index);
应该写在哪里?
QModelIndex index  我如何传参数?
离线hover_sky

只看该作者 10楼 发表于: 2010-02-26
QObject::connect(ui.tableView, SIGNAL(clicked(QModelIndex )), this, SLOT(updateDetailedView(QModelIndex)));


不用emit
离线liwenfu24
只看该作者 11楼 发表于: 2010-02-27
There is no Chinese input on my Linux box, so I use English here.

I found a suitable example for this program:
C++ GUI programing with Qt4 => chapter 13 => staff manager
The source code can be downloaded from the internet.

Thank all of you for your kind help.
离线sun83819
只看该作者 12楼 发表于: 2010-02-28
引用第11楼liwenfu24于2010-02-27 02:20发表的  :
There is no Chinese input on my Linux box, so I use English here.
I found a suitable example for this program:
C++ GUI programing with Qt4 => chapter 13 => staff manager
The source code can be downloaded from the internet.
.......


hey~~friend:
there is no "staff manager" progam in C++ GUI programing with Qt4!


C++ GUI Programming with Qt 4

ISBN 0-13-124072-2

The root of the examples directory contains examples.pro.
If you execute

    qmake examples.pro
    make

(nmake if you use Visual C++), the examples for all chapters
with complete cross-platform examples will be built.

1. Getting Started
        chap01/age
        chap01/hello
        chap01/quit
2. Creating Dialogs
        chap02/find
        chap02/gotocell1
        chap02/gotocell2
        chap02/sort
3. Creating Main Windows
        chap03/spreadsheet
4. Implementing Application Functionality
        chap04/spreadsheet
5. Creating Custom Widgets
        chap05/hexspinbox
        chap05/iconeditor
        chap05/iconeditorplugin
        chap05/plotter
6. Layout Management
        chap06/findfile1
        chap06/findfile2
        chap06/findfile3
        chap06/mailclient
        chap06/mdieditor
        chap06/preferences
        chap06/splitter
7. Event Processing
        chap07/ticker
8. 2D and 3D Graphics
        chap08/oventimer
        chap08/tetrahedron
9. Drag and Drop
        chap09/projectchooser
10. Item View Classes
        chap10/cities
        chap10/colornames
        chap10/coordinatesetter
        chap10/currencies
        chap10/directoryviewer
        chap10/flowchartsymbolpicker
        chap10/regexpparser
        chap10/settingsviewer
        chap10/teamleaders
        chap10/trackeditor
12. Input/Output
        chap12/imageconverter
        chap12/imagespace
        chap12/tidy
13. Databases
        chap13/cdcollection
14. Networking
        chap14/ftpget
        chap14/httpget
        chap14/spider
        chap14/tripplanner
        chap14/tripserver
        chap14/weatherballoon
        chap14/weatherstation
15. XML
        chap15/domparser
        chap15/saxhandler
18. Multithreading
        chap18/imagepro
        chap18/semaphores
        chap18/threads
        chap18/waitconditions
19. Creating Plugins
        chap19/basiceffectsplugin
        chap19/cursorplugin
        chap19/extraeffectsplugin
        chap19/textart
20. Platform-Specific Features
        chap20/addressbook
        chap20/bouncer
        chap20/mediaplayer
        chap20/tictactoe
快速回复
限100 字节
 
上一个 下一个