PDA

View Full Version : How do I add new tab to QTabWidget



pcmantinker
5th June 2008, 01:48
Sorry if this has been asked already. I just haven't found a related enough thread to point me in the right direction. I have a program that I have coded in C# .NET 3.5 thus far and want to port it to the best of my ability to C++ with Qt 4.4.0. I want to develop a tabbed text editor so that I don't have to deal with MDI windows. It's the start of an IDE for an E-Blah Forum template editor. I have the GUI setup in C# .NET currently. I have the GUI mimicked in Qt Designer and have a QTabWidget already setup there. I'm just trying to figure out how to add a tab to a QTabWidget. I just need to know the correct syntax and class structure.

I understand that I must have a QTabWidget object to place tabs into, which I have, but how do I add new tabs? Do I need to create a class for each kind of tab to add to the main QTabWidget?

Here is the code that I have to add a new tab right now:

tab = new QTabWidget;
tabDocument->addTab(tab, tr("General"));
tab is defined here:

// defaulttab.h
// Default Tab for tab interface

class tab : public QWidget
{
Q_OBJECT

public:
tab(QWidget *parent = 0);
};
The name tab is just a test. I was trying to get a tab to show up and make it easy for me to do so with a short name.

With the above code, I don't get a compile error. It seems to all be ok. However, I get a SIGSEGV error when running the event to trigger the addtab method.

janus
5th June 2008, 09:10
Hi,


QWidget *newTab = new QWidget(myTabWidget);
myTabWidget->addTab(newTab, tr("name"));

pcmantinker
6th June 2008, 04:24
Thanks. I appreciate your help.