を拡張する次のクラスがありますが、目的のスロットに信号をQListWidget
接続できないようです。doubleClicked
これがVS2012で実装されたコードです。アイデアは、アイテムをダブルクリックして編集できるようにすることです。シグナルをコンストラクターのスロットに接続しますが、デバッガーで実行してもスロットが呼び出されません。
# .h file
class DisplayFeed :
public QListWidget
{
Q_OBJECT
public:
DisplayFeed(QWidget *parent, Logic *logic, int xpos, int ypos, int width, int height, std::string color);
~DisplayFeed(void);
void setColor(std::string color);
void refresh(std::vector<Event*> *thingsToInclude);
private:
Logic* logic;
private slots:
void editItem(QEventStore *item);
};
以下は .cpp ファイルです。QEventStore
伸びQListWidgetItem
ます。他のコードが機能しなかった場合に備えて、MessageBox を配置してシステムもテストしました。
# .cpp file, only relevant methods included
DisplayFeed::DisplayFeed(QWidget *parent, Logic *logic, int xpos, int ypos, int width, int height, std::string color)
: QListWidget(parent)
{
this->logic = logic;
setGeometry(xpos, ypos, width, height);
setColor(color);
QObject::connect(this, SIGNAL(itemClicked(QEventStore*)), this, SLOT(editItem(QEventStore*)));
show();
}
void DisplayFeed::editItem(QEventStore *item){
QMessageBox::information(this,"Hello!","You clicked \""+item->text()+"\"");
QEventEditor *editor = new QEventEditor(item->getEvent());
}