PDA

View Full Version : Problem using QTabWidget



UchihaMk
2nd September 2012, 23:29
Hi All,
i am at the first message i this Forum, i have a very bad problem with QTabWidget on my Ubuntu 12.04 vm. Basically in my application i have only two tabs but when i switch from one to another the two different contents will be displayed in both of them.

So i tried to create a SLOT for the signal changeOccured(int) in order to create a qApp->processEvents(QEventLoop::AllEvents); (i suppose it can help me to solve the problem) but the results is this:

main.cpp:(.text+0xeb4): undefined reference to `MyTabWidget::MyTabWidget(QWidget*)'
collect2: ld returned 1 exit status


I post my code:



//main.cpp
#include "MyTabWidget.h"


using namespace std;
//definizione della classe MyTabWidget

int main(int argc, char *argv[]){
[ .....omitted.... declaration of widget and layout....]
QWidget *centralWidget = new QWidget(&w);
centralWidget->setFixedSize(1200,200);
MyTabWidget *tabs = new MyTabWidget(centralWidget);
tabs->setDocumentMode(true);
tabs->setFixedSize(1200, 800);
tabs->addTab(window0,"Controllo");
tabs->addTab(window,"Registrazione");
tabs->setTabsClosable(false);
QObject::connect(tabs,SIGNAL(currentChanged(int)), tabs,SLOT(prova()));





//myTabWidget.h File

#ifndef MYTABWIDGET_H
#define MYTABWIDGET_H

#include <QTabWidget>
#include <QMessageBox>
#include <QString>


class MyTabWidget : public QTabWidget{
Q_OBJECT

public:
explicit MyTabWidget(QWidget* parent=0);
~MyTabWidget();

private slots:
//Slot that is called when Tab selection changes
void prova(int);

};
#endif




//MyTabWidget.cpp
#include <QTabWidget>
#include <QMessageBox>
#include <QString>
#include "MyTabWidget.h"

void MyTabWidget::prova(int) : QTabWidget(int){
QMessageBox* msg = new QMessageBox(this->parentWidget());
msg->setWindowTitle("Hello !");
msg->setText("Selected Tab index is : "+ QString::number(index));
msg->show();
}

MyTabWidget::MyTabWidget(QWidget *parent) : QTabWidget(parent){
// this->setParent(parent);
cout<<"creato"<<endl;
//connect(MyTabWidget , SIGNAL(currentChanged(int)),this,SLOT(currentChang edSlot(void)));
}


I read so many articles and tutorial even on this forum, but i cannot think about a solution for my problem.

Can anyone please help me?

Viper666
3rd September 2012, 10:04
void prova(int); method prova has a int argument

QObject::connect(tabs,SIGNAL(currentChanged(int)), tabs,SLOT(prova(/*miss int*/)));

QObject::connect(tabs,SIGNAL(currentChanged(int)), tabs,SLOT(prova(int)));
And I think whole your code is shit.

d_stranz
3rd September 2012, 18:27
undefined reference to `MyTabWidget::MyTabWidget(QWidget*)'

It looks like you aren't linking MyTabWidget.o into your executable. Including the header file in the main.cpp program only gets you halfway there. You also have to compile and link in the MyTabWidget.cpp file.


@Viper666: And I think whole your code is shit.

Maybe you should post some of the code you wrote when you were first learning, show us all how great beginner code should be written. (Not to mention the fact that your answer didn't address the problem that the OP was asking about in the first place).

UchihaMk
3rd September 2012, 22:29
Hi All...
Thanks very much for both suggestions. I will try to make my code better.

I have pass through the including library and code into the project directly in the CMakeLists.txt but even if i use in the currentChange method this code




qApp->processEvents(QEventLoop::AllEvents);



when i switch from one page of the tab to another the content is fused togheter...

Anyone had this problem and know how to help my out of this situation?

norobro
4th September 2012, 02:30
The code that you have shown works fine with a couple of tweaks:
#include <QtGui>
class MyTabWidget : public QTabWidget
{
Q_OBJECT
public:
MyTabWidget(QWidget *parent = 0) : QTabWidget(parent) {
qDebug() << "created";
}
public slots:
void prova(int index){
QMessageBox* msg = new QMessageBox(this->parentWidget());
msg->setWindowTitle("Hello !");
msg->setText("Selected Tab index is : "+ QString::number(index));
msg->show();
}
};

int main(int argc, char *argv[]){
QApplication app(argc, argv);
QMainWindow w;
QWidget *centralWidget = new QWidget(&w);
centralWidget->setFixedSize(1200,800);
MyTabWidget *tabs = new MyTabWidget(centralWidget);
tabs->setDocumentMode(true);
tabs->setFixedSize(1200, 200);
tabs->addTab(new QLabel("Page 1"),"Controllo");
tabs->addTab(new QLabel("Page 2"),"Registrazione");
tabs->setTabsClosable(false);
QObject::connect(tabs,SIGNAL(currentChanged(int)), tabs,SLOT(prova(int)));
w.setCentralWidget(centralWidget);
w.show();
return app.exec();
}
#include "main.moc"


What do "window" and "window0" point to?

UchihaMk
4th September 2012, 21:19
So i show you all the code:



#include "mainwindow.h"
#include "registrazione.h"
#include <QtGui>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkImageViewer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkJPEGReader.h>
#include <QCheckBox>
#include <QVTKWidget.h>
#include "MyTabWidget.h"


using namespace std;


int main(int argc, char *argv[]){


QApplication a(argc, argv);

MainWindow w;

QPushButton *Dati = new QPushButton("Inserisci dati");
Dati->setFixedHeight(20);
Dati->setFixedWidth(150);

QPushButton *Registrazione = new QPushButton("Avvia registrazione");
Registrazione->setFixedHeight(20);
Registrazione->setFixedWidth(150);
Registrazione->setEnabled(false);

QPushButton *Seleziona = new QPushButton("Point Pick");
Seleziona->setEnabled(false);
Seleziona->setFixedHeight(20);
Seleziona->setFixedWidth(150);

QPushButton *impS = new QPushButton("Cambia source");
impS->setFixedHeight(20);
impS->setFixedWidth(150);

QPushButton *impT = new QPushButton("Cambia target");
impT->setFixedHeight(20);
impT->setFixedWidth(150);

QPushButton *Carica = new QPushButton("Carica PCD");
Carica->setFixedHeight(20);
Carica->setFixedWidth(150);

QPushButton *Controlla = new QPushButton("Controlla");
Controlla->setFixedHeight(20);
Controlla->setFixedWidth(150);
Controlla->setEnabled(false);

QLabel *l0 = new QLabel("Posizione della point cloud da controllare");

QLabel *l1 = new QLabel("Posizione della point cloud sorgente");

QLabel *l2 = new QLabel("Posizione della point cloud destinazione");

QLabel *interazioni = new QLabel("Interazioni: ");
interazioni->setFixedWidth(150);
QTextEdit *testo0 = new QTextEdit("");
testo0->verticalScrollBar()->setVisible(false);
testo0->setFixedHeight(20);
testo0->setFixedWidth(300);
testo0->setEnabled(false);


QTextEdit *testo1 = new QTextEdit("");
testo1->verticalScrollBar()->setVisible(false);
testo1->setFixedHeight(20);
testo1->setFixedWidth(300);
testo1->setEnabled(false);

QTextEdit *testo2 = new QTextEdit("");
testo2->setFixedHeight(20);
testo2->setFixedWidth(300);
testo2->setEnabled(false);
testo2->verticalScrollBar()->setVisible(false);

QVTKWidget *widget0 = new QVTKWidget;
widget0->setVisible(false);


QVTKWidget *widget = new QVTKWidget;
widget->setVisible(false);


QWidget *window0 = new QWidget();

QWidget *window = new QWidget();

QHBoxLayout *ly0 = new QHBoxLayout();
ly0->addWidget(l0);
ly0->addWidget(testo0);
ly0->addWidget(Carica);
ly0->addWidget(Controlla);

QHBoxLayout *ly1 = new QHBoxLayout();
ly1->addWidget(l1);
ly1->addWidget(l2);

QHBoxLayout *ly2 = new QHBoxLayout();
ly2->addWidget(testo1);
ly2->addWidget(impS);
ly2->addWidget(testo2);
ly2->addWidget(impT);


QHBoxLayout *ly3 = new QHBoxLayout();
ly3->addWidget(interazioni);
ly3->addWidget(Registrazione);
ly3->addWidget(Seleziona);


QVBoxLayout *layout0 = new QVBoxLayout();
layout0->addLayout(ly0);
layout0->addWidget(widget0);

QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(Dati);
layout->addLayout(ly1); layout->addLayout(ly2); layout->addLayout(ly3);
layout->addWidget(widget);


window0->setLayout(layout0);
window0->setGeometry(1000,0,1200,800);
window->setVisible(false);
window0->show();


window->setLayout(layout);
window->setGeometry(1000,0,1200,800);
window->setVisible(false);
window->show();

QWidget *centralWidget = new QWidget(&w);
centralWidget->setFixedSize(1200,200);


MyTabWidget *tabs = new MyTabWidget(centralWidget);
tabs->setDocumentMode(false);
tabs->setFixedSize(1200, 800);
tabs->addTab(window0,"Controllo");
tabs->addTab(window,"Registrazione");
tabs->setTabsClosable(false);
tabs->update();
QObject::connect(tabs,SIGNAL(currentChanged(int)), tabs,SLOT(prova(int)));

w.setCentralWidget(centralWidget);
w.setGeometry(1000,0,1200,800);
w.setWindowTitle("Progetto di Elaborazione tridimensionale");
w.show();

w.setVisualizer(testo0, Carica,Controlla, widget0);
w.setVisualizer(Dati, Registrazione,testo1,testo2,widget,impS,impT,Selez iona);//, Plan, Radious);

return a.exec();
}

Viper666
6th September 2012, 17:28
It looks like you aren't linking MyTabWidget.o into your executable. Including the header file in the main.cpp program only gets you halfway there. You also have to compile and link in the MyTabWidget.cpp file.



Maybe you should post some of the code you wrote when you were first learning, show us all how great beginner code should be written. (Not to mention the fact that your answer didn't address the problem that the OP was asking about in the first place).
Wow i wanted say that he can see code and find some bugs and make it better this is all

norobro
7th September 2012, 01:35
What does the setVisualizer method do?

UchihaMk
7th September 2012, 21:58
void MainWindow::setVisualizer(QTextEdit *t0, QPushButton *c, QPushButton *ct, QVTKWidget *w){
testo0 = t0;
Cambia = c;
Controlla = ct;
finestra0 = w;

QObject::connect(c, SIGNAL(clicked()), this ,SLOT(impostaC()));
QObject::connect(ct, SIGNAL(clicked()), this ,SLOT(controllaPCD()));
//finestra0->show();
//aggiornaFinestra(daControllare,finestra0);
}

void MainWindow::setVisualizer(QPushButton *d, QPushButton *r, QTextEdit *t1, QTextEdit *t2, QVTKWidget *w, QPushButton *s, QPushButton *t, QPushButton *sel, QWidget *lgr){
Dati = d; //inserire entrambi i percorsi contemporaneamente
Registrazione = r; //bottone che avvia la registrazione
ImpS=s; //cambiare percorso sorgente
ImpT=t; //cambiare percorso target
Seleziona=sel; //bottone selezione pointPick
testo1 = t1; //inserimento percorso source
testo2 = t2; //inserimento percorso target
finestra = w;
loggerBase=lgr;

//routine di risposta
QObject::connect(d, SIGNAL(clicked()), this ,SLOT(reg()));
QObject::connect(r, SIGNAL(clicked()), this ,SLOT(esegui()));
QObject::connect(s, SIGNAL(clicked()), this ,SLOT(impostaS()));
QObject::connect(t, SIGNAL(clicked()), this ,SLOT(impostaT()));
QObject::connect(sel, SIGNAL(clicked()), this ,SLOT(selezionatore()));

//aggiornaFinestra(daControllare,finestra);
//rendere visibile la finestra di
//finestra->setVisible(true);
//finestra->show();
return;
}



This is the code, is a method of union from the main code and the class MainWindow, it simply set the pointer to the Widget in main.cpp and create the slot for some signal