Important: Please read the Qt Code of Conduct -

How to connect a signal of a widget, which is created latter in the program?

  • I have QTableWidget...I declared it in class declaration...
    @.QTableWidget *filesTable;

    I am creating this QTable in some function of that class
    ..after clicking on a button....(multiple files created if multiple times clicked.)

    Now i want to get "customContextMenuRequested" of that table.....
    connect(Table,SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(ProvideContextMenu(const QPoint &)));
    in constructor, my program crashes as i not yet allocated memory for that table.....

    If i declare table i.e
    Table= new QTableWidget(this);
    in constructor i create multiple tables....

    So what should i do to solve this problem?

  • Hi,

     you can clear the table before adding data in to the table.i hope it will help u

  • When you create the table add the signal just after. Or create a wrapper method that creates and connects the table. You are not constrained to connect signals only from within an object, you can connect at any time and from anywhere if they are public.

  • You can only create connections at a place in your code where:

    Both objects exist

    You can access pointers to both objects

    That means that you simply cannot create a connection to an object that has not been created yet. Why don't you create the connection at the place where you created the table?

  • [quote author="cdeepak" date="1329374871"]Hi,

     you can clear the table before adding data in to the table.i hope it will help u[/quote]

    No i want to display all the tables.....multiple tables are shown in tab widget..

  • ok thank u...

Log in to reply