-
How to call a dialog from a mainwindow
I want to build an interface and I need to link a pushbutton in a mainwindow with a dialog. Both were made in Qt Designer. I tried some answers that I saw in others thread but I think it doesn't help me. So, here it goes my codes:
Mainwindow: telainicial (.h/.cpp)
Dialog: simples (.h/.cpp)
telainicial.h
Code:
#ifndef TELAINICIAL_H
#define TELAINICIAL_H
#include <QMainWindow>
#include "ui_telainicial.h"
class telainicial
: public QMainWindow,
public Ui
::telainicial { Q_OBJECT
public:
private slots:
void telasimples();
};
#endif // TELAINICIAL_H
telainicial.cpp
Code:
#include <QtGui>
#include "telainicial.h"
#include "simples.h"
telainicial
::telainicial(QWidget *parent
) :
{
setupUi(this);
connect(lentesimplesButton, SIGNAL(clicked()), this, SLOT(telasimples()));
}
void telainicial::telasimples(){
//code goes here
};
simples.h
Code:
#ifndef SIMPLES_H
#define SIMPLES_H
#include <QDialog>
#include "ui_simples.h"
class simples
: public QDialog,
public Ui
::simples { Q_OBJECT
public:
};
#endif
simples.cpp
Code:
#include "simples.h"
#include <QtGui>
simples
::simples(QWidget *parent
) :
{
setupUi(this);
}
The mains files are similiar like this:
Code:
#include <QtGui/QApplication>
#include "telainicial.h"
int main(int argc, char *argv[])
{
telainicial mainwindow;
mainwindow.show();
return app.exec();
}
Can somebody help me?
-
Re: How to call a dialog from a mainwindow
I've tried:
simples dialog(this);
dialog.exec();
But it fails. The follow problem is detected:
undifined reference to 'simple::simple(QWidget*)'
undifined reference to 'vtable for simples'
undifined reference to 'vtable for simples'
collect2: Id returned 1 exit status
Someone knows what is it?
-
Re: How to call a dialog from a mainwindow
Run qmake and then build your program again. Btw. your class is called "simples" and you are calling the constructor as "simple".
-
Re: How to call a dialog from a mainwindow
My mistake. The follow problem was detected:
undifined reference to 'simples::simples(QWidget*)'
It's not a problem about compilation I think. I'm using the Qt Creator to do everything, like designer the ui files and compile the program. Is there any problem to do it?
-
Re: How to call a dialog from a mainwindow
Again, check if you actually implemented the simples constructor.
-
Re: How to call a dialog from a mainwindow
Yes, it works individually. But not when I call it by mainwindow. All my constructors are correct. I just don't know what to do... I've tried everything... Is it better to make the .pro file in the Qt Command Prompt? If you can run my codes on your pc (try to do it in Qt Creator)...
-
Re: How to call a dialog from a mainwindow
What "works individually"? The .pro file is not an issue here, the linker can't find the implementation of your constructor. Could you post the contents of the offending method?
-
Re: How to call a dialog from a mainwindow
I don't know exactly what are you asking for. I'm a beginner. Can I send my files to you by email? Sorry bother you, but it's important... :/
-
Re: How to call a dialog from a mainwindow
Please post the body of the constructor of class "simples". I hope you know what a constructor is... If not, you should first learn at least basics of C++ before taking on Qt.
-
Re: How to call a dialog from a mainwindow
I try to search in my files about C++ something connect to constructor class but I don't find a good answer. So, I again ask you with you can give me a example of constructor class. I'm still lost here. The following compile output appear when I run telainicial mainwindow:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\TelaPrincipal.exe debug/main.o debug/telainicial.o debug/moc_telainicial.o -L"f:\QT\2010.02.1\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Users/Luiz Paulo/Documents/TelaPrincipal'
mingw32-make: Leaving directory `C:/Users/Luiz Paulo/Documents/TelaPrincipal'
[r]debug/telainicial.o:C:\Users\Luiz Paulo\Documents\TelaPrincipal/telainicial.cpp:16: undefined reference to `simples::simples(QWidget*)'
debug/telainicial.o: In function `~simples':
C:\Users\Luiz Paulo\Documents\TelaPrincipal/simples.h:7: undefined reference to `vtable for simples'
C:\Users\Luiz Paulo\Documents\TelaPrincipal/simples.h:7: undefined reference to `vtable for simples'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\TelaPrincipal.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project TelaPrincipal
When executing build step 'Make'[/r]
-
Re: How to call a dialog from a mainwindow
1) run qmake from the menu
2) rebuild your project
3) if it still doesn't work, post simples.h and simples.cpp if they are now different to your first post
-
Re: How to call a dialog from a mainwindow
It's already posted on top. Can you see? There are 4 codes... 2 of them are this codes...
-
Re: How to call a dialog from a mainwindow
My bet is you didn't add simples.cpp to SOURCES in your project file. At least I can't see simples.o being linked into the binary.
-
Re: How to call a dialog from a mainwindow
Can be... now I tried it but the compilation stop to work and when I check the compile output this message was shown:
Running build steps for project TelaPrincipal...
Starting: f:/qt/2010.02.1/qt/bin/qmake.exe C:/Users/Luiz Paulo/Documents/TelaPrincipal/TelaPrincipal.pro -spec win32-g++ -r
c:\Users\Luiz Paulo\Documents\TelaPrincipal\TelaPrincipal.pro:15 : Parse Error ('simples.cpp')
Error processing project file: C:/Users/Luiz Paulo/Documents/TelaPrincipal/TelaPrincipal.pro
Exited with code 3.
Error while building project TelaPrincipal
When executing build step 'QMake'
Just one doubt... Which simples's files have to be in the same folder that the mainwindow's folder? Cause when I made both, I made it individually, so each one have a specific folder. But, I copy and put the simples.h, simples.cpp, ui_simples.h in the mainwindow's folder...
-
Re: How to call a dialog from a mainwindow
Did you add simples.cpp to the SOURCES variable or did you just put it in the project file in a random place?
You can place the actual files anywhere you want as long as you tell the compiler where to find them.
-
Re: How to call a dialog from a mainwindow
How I tell the compiler where is the dialog files? Sorry the stupid question... I'm noob about Qt...
-
Re: How to call a dialog from a mainwindow
You need a proper project file. Could you post its contents?
-
Re: How to call a dialog from a mainwindow
The files .pro are below:
telainicial.pro:
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2010-05-14T10:13:43
#
#-------------------------------------------------
QT += opengl
TARGET = TelaPrincipal
TEMPLATE = app
SOURCES += main.cpp\
telainicial.cpp
simples.cpp
HEADERS += telainicial.h
FORMS += telainicial.ui
simples.pro:
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2010-05-14T10:47:49
#
#-------------------------------------------------
QT += opengl
TARGET = LenteSimples
TEMPLATE = app
SOURCES += main.cpp\
simples.cpp
HEADERS += simples.h
FORMS += simples.ui
Are this files you want to see?
-
Re: How to call a dialog from a mainwindow
Look at your first project file. simples.cpp is not part of the SOURCES variable.
-
Re: How to call a dialog from a mainwindow
It was missing a "\" after telainicial.cpp... I corrected it.
But where I put the local where the dialog (simples) is located?
-
Re: How to call a dialog from a mainwindow
Either provide the proper path in the SOURCES variable or use the DEPENDPATH variable.
-
Re: How to call a dialog from a mainwindow
Thanks!! Now it works!!! I'm so gratefull!
Now... using this post... Do you know how I custumize a pushbutton? Cause I'm programing in Windows and The default button is very common. I want to rounded it... make a shadow... something like this, you know...
-
Re: How to call a dialog from a mainwindow
Search the forum for similar questions. If you don't find an answer, start a new thread.
-
Re: How to call a dialog from a mainwindow
wysota,
Again, the similar problem appeared. Everything was working after I indexed corectly the .cpp file and .h file. But, suddently, when I edited a file in the mainwindow and I compiled it again, an error message showed up.
telainicial.cpp:3:21: error: simples.h: No such file or directory
telainicial.cpp:4:18: error: prog.h: No such file or directory
telainicial.cpp:5:19: error: trans.h: No such file or directory
telainicial.cpp:6:20: error: config.h: No such file or directory
telainicial.cpp: In member function 'void telainicial::telasimples()':
telainicial.cpp:21: error: 'simples' was not declared in this scope
telainicial.cpp:21: error: expected ';' before 'dlg'
telainicial.cpp:22: error: 'dlg' was not declared in this scope
telainicial.cpp: In member function 'void telainicial::telaprog()':
telainicial.cpp:26: error: 'prog' was not declared in this scope
telainicial.cpp:26: error: expected ';' before 'dlg'
telainicial.cpp:27: error: 'dlg' was not declared in this scope
telainicial.cpp: In member function 'void telainicial::telatrans()':
telainicial.cpp:31: error: 'trans' was not declared in this scope
telainicial.cpp:31: error: expected ';' before 'dlg'
telainicial.cpp:32: error: 'dlg' was not declared in this scope
telainicial.cpp: In member function 'void telainicial::telaconfig()':
telainicial.cpp:36: error: 'config' was not declared in this scope
telainicial.cpp:36: error: expected ';' before 'dlg'
telainicial.cpp:37: error: 'dlg' was not declared in this scope
mingw32-make[1]: Leaving directory `E:/Luiz Paulo/TelaPrincipal'
mingw32-make: Leaving directory `E:/Luiz Paulo/TelaPrincipal'
mingw32-make[1]: *** [debug/telainicial.o] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project TelaPrincipal
When executing build step 'Make'
It looks the mainwindow doesn't find now the dialogs indexed on it. I already checked all located in .pro file and everything is correctly. I'm now confused...
I have a version that I saved on my flash that is working... but the codes are the same. I don't know what is going on...
-
Re: How to call a dialog from a mainwindow
Post the file telainicial.cpp & h how they look currently. Did you change the location of your included files relatively to the "telainicial.cpp" file? Are they in a subfolder?
From the compiler output it appears that your header files were not found. Are you sure they are where they were last time you compiled it?
Check all of this. Something has changed certainly.
-
Re: How to call a dialog from a mainwindow
telainicial.cpp:
Code:
#include <QtGui>
#include "telainicial.h"
#include "simples.h"
#include "prog.h"
#include "trans.h"
#include "config.h"
telainicial
::telainicial(QWidget *parent
) :
{
setupUi(this);
connect(lentesimples, SIGNAL(clicked()), this, SLOT(telasimples()));
connect(lenteprog, SIGNAL(clicked()), this, SLOT(telaprog()));
connect(transmissao, SIGNAL(clicked()), this, SLOT(telatrans()));
connect(configuracoes, SIGNAL(clicked()), this, SLOT(telaconfig()));
}
void telainicial::telasimples(){
simples dlg(this);
dlg.exec();
}
void telainicial::telaprog(){
prog dlg(this);
dlg.exec();
}
void telainicial::telatrans(){
trans dlg(this);
dlg.exec();
}
void telainicial::telaconfig(){
config dlg(this);
dlg.exec();
};
telainicial.h
Code:
#ifndef TELAINICIAL_H
#define TELAINICIAL_H
#include <QMainWindow>
#include "ui_telainicial.h"
class telainicial
: public QMainWindow,
public Ui
::telainicial { Q_OBJECT
public:
private slots:
void telasimples();
void telaconfig();
void telaprog();
void telatrans();
};
#endif // TELAINICIAL_H
telainicial.pro
Code:
# -------------------------------------------------
# Project created by QtCreator 2010-05-14T10:13:43
# -------------------------------------------------
QT += opengl
TARGET = TelaPrincipal
TEMPLATE = app
SOURCES += main.cpp \
telainicial.cpp \
../Config/config.cpp \
../LenteSimples/simples.cpp \
../Progressiva/prog.cpp \
../Transmissao/trans.cpp
HEADERS += telainicial.h \
../Config/config.h \
../LenteSimples/simples.h \
../Progressiva/prog.h \
../Transmissao/trans.h
FORMS += telainicial.ui
OTHER_FILES +=
All dialog's folders are in the same folder, including the mainwindow's folder. I already have indexed the .h and .cpp files thounsand times but it just doesn't work. Can you try in your pc? I can send it by email...
-
Re: How to call a dialog from a mainwindow
I see some files are in subfolders. Do you have an additional include directories set to these subfolders? Or try adding a subfolder name to the include command.
The compiler output is clear. It can't find all the files that are in subfolders. Focus on that.