Results 1 to 4 of 4

Thread: How to connect two Tabs in Applicatin?

  1. #1
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default How to connect two Tabs in Applicatin?

    Hello.
    I have an Application with two Tabs:
    - Tab1 (described in tab1.h file) has a QLineEdit widget.
    - Tab2 (described in tab2.h file) has a QTableWidget widget.
    They are added to Application in tabDialog.h file like this:
    Qt Code:
    1. tabWidget->addTab(Tab1,"Tab1");
    2. tabWidget->addTab(Tab2,"Tab2");
    3. QVBoxLayout *layout = new QVBoxLayout;
    4. layout->addWidget(tabWidget);
    5. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 
    When user run my Application, text in QTableWidgetItem (in Tab2 Table) have to be changed when user press "Enter" in QLineEdit widget (in Tab1).

    Could you please give me some idea how and where to connect SIGNAL(returnPressed()) from Tab1 with public slot from Tab2?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to connect two Tabs in Applicatin?

    They are added to Application in tabDialog.h (...)
    Why are you creating your objects in a header ? And where exactly is the code called ? Is it inline constructor ?
    About connection : connect tabs once after adding them to widget:
    Qt Code:
    1. tabWidget->addTab(Tab1,"Tab1");
    2. tabWidget->addTab(Tab2,"Tab2");
    3. connect( Tab1, SIGNAL(returnPressed()), Tab2, SLOT(publicSlotFromTab2()) );
    4. QVBoxLayout *layout = new QVBoxLayout;
    5. layout->addWidget(tabWidget);
    6. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default Re: How to connect two Tabs in Applicatin?

    Quote Originally Posted by stampede View Post
    Why are you creating your objects in a header ?
    I create them in .cpp files. I have .h and .cpp files, as it have to be.
    Quote Originally Posted by stampede View Post
    And where exactly is the code called ?
    In main.cpp like this:
    Qt Code:
    1. int main(int argc,char *argv[])
    2. {
    3. QApplication app(argc,argv);
    4. tabDialog tabdialog;
    5. return tabdialog.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by stampede View Post
    connect( Tab1, SIGNAL(returnPressed()), Tab2, SLOT(publicSlotFromTab2()) );
    This does not work. Tab2 in my Application does not change it's Table when user press "Enter" in QLineEdit in Tab1. Maybe I have to push Tab2 to "redraw" itself somehow? But how?

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to connect two Tabs in Applicatin?

    This does not work
    You mean that signal is not delivered to slot ? Try to see if connection call is ok:
    Qt Code:
    1. bool status = connect(Tab1, ... );
    2. qDebug() << "connection status: " << status;
    To copy to clipboard, switch view to plain text mode 
    Add some qDebugs in the slot itself as well and see if you can see them after pressing "return".

Similar Threads

  1. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 12:20
  2. Replies: 16
    Last Post: 16th February 2010, 13:17
  3. Nice looking tabs
    By frikkasoft in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2008, 14:15
  4. Firefox-like tabs
    By sdfisher in forum Qt Programming
    Replies: 7
    Last Post: 10th March 2007, 06:51
  5. Replies: 4
    Last Post: 10th November 2006, 15:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.