Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal & Slot problem occured by defining own slot

Signal & Slot problem occured by defining own slot

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Binary91
    wrote on last edited by
    #1

    Hello,

    I have the following files with my own class derived by QWigets:
    main.h:
    @#include "qt_windows.h"
    #include <QApplication>
    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QTableWidget>
    #include <QCheckBox>
    #include <QObject>

    class window_main : public QWidget
    {
    Q_OBJECT

    public:
    QVBoxLayout *layout;
    QTableWidget *table;

    window_main(int rows, int columns);
    

    public slots:
    void click_handler(const QModelIndex &index);
    };@

    main.cpp:
    @#include "main.h"
    #include "qt_windows.h"
    #include <QApplication>
    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QTableWidget>
    #include <QCheckBox>
    #include <QObject>

    int main(int argc, char** args)
    {
    FreeConsole();
    QApplication app(argc, args);

    window_main window(50, 7);
     
    window.layout->addWidget(window.table);
    window.setLayout(window.layout);
     
    window.setWindowTitle("Calculator");
    window.showMaximized();
    app.exec&#40;&#41;;
    

    return 0;
    }

    window_main::window_main(int rows, int columns)
    {
    layout = new QVBoxLayout(this);
    table = new QTableWidget(rows, columns);

    connect(this->table, SIGNAL(clicked(const QModelIndex &index)), this, SLOT(click_handler(const QModelIndex &index)));
    

    }

    void window_main::click_handler(const QModelIndex &index)
    {
    this->showMinimized();
    }@

    When I click on the table, nothing happens. Does anyone have a clue why?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      You do not need to give the argument name, remove the index name in your connect.
      That might do the trick.
      Also, what does your output window says?? IT will notify you if an connection could not be made

      Greetz, Jeroen

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Binary91
        wrote on last edited by
        #3

        Thank's a lot, that was it!

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Binary91
          wrote on last edited by
          #4

          Another question:
          Now I try to get information about the clicked cell. What I tried so far is:
          [code]
          void window_main::click_handler(const QModelIndex& index)
          {
          int index_row = index.row(), index_column = index.column();
          QTableWidgetItem* item = this->table->item(index_row, index_column);
          if(item != NULL)
          {
          QMessageBox *msgbox = new QMessageBox(this);
          QString title = "Item selected", text = item->text();
          msgbox->information(NULL, title, text, QMessageBox::Ok);
          }
          }[/code]
          Problem is, that [code]item[/code] is always NULL... why?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on last edited by
            #5

            Ok, as I know now I have to create QTableWidgetItems first and then add them to QTableWidget... sounds logical, BUT that won't solve my problem, because I have several different widgets in my QTableWidget (checkboxes, buttons etc.), which I can't put in a QTableWidgetItem but instead directly via setCellWidget(QWidget*)..

            Now my question:
            How is it possible to get the content of a clicked cell (QTableWidget), when it's contents are placed via setCellWidget?
            Background is, that I want to detect if user clicks first cell in a row --> then I'd like to get the checkstate of every QCheckBox in every cell in that row... so I have to get the CheckBox by only having a pointer to a cell (QModelIndex), not to the checkboxes itsself...
            I need something like a method to get the child elements of a cell...

            Any clues how to solve this?

            EDIT:
            Solved -- created Widgets for every cell and got a pointer to them via QTableWidget::cellWidget(row, column)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved