HOw to display new windows
-
I created a new project myProject, and added a button to formA. I added another qt ui class FormB which created .ui .cpp and .h
What i did is tried to do was display the second formB to the user with the code below, using similar java experience.This worked seemingly fine on the simulator(compiled without errors and ran). But when i tried executing on real symbian device, compiler gives
undeclared reference formB::formB(QWidget*).
Please, is there anything i'm doing wrong, or is there a better way to do this. Assuming formA is a login for that displays formB, after clicking an OK button.If it helps, here are the classes for the two files
formA.h
@
#ifndef FORMA_H
#define FORMA_H#include <QMainWindow>
#include <formb.h>
namespace Ui {
class forma;}
class forma : public QMainWindow
{
Q_OBJECTpublic:
explicit forma(QWidget *parent = 0);
~lock();private:
Ui::forma *ui;private slots:
void on_formbButton_clicked(); void on_unlockButton_clicked();
};
#endif // FORMA_H
@
forma.cpp
@
#include "forma.h"
#include "ui_forma.h"
#include "formb.h"forma::forma(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::forma)
{
ui->setupUi(this);
}forma::~forma()
{
delete ui;
}void forma::on_unlockButton_clicked()
{
this->close();
}void forma::on_iceButton_clicked()
{
formb *j = new formb();j->showMaximized();
}
@formb.h
@
#ifndef FORMB_H
#define FORMB_H#include <QWidget>
namespace Ui {
class formb;
}class formb : public QWidget
{
Q_OBJECTpublic:
explicit formb(QWidget *parent = 0);
~formb();private:
Ui::formb *ui;
};#endif // FORMB_H
@
formb.cpp
@
#include "formb.h"
#include "ui_formb.h"formb::formb(QWidget *parent) :
QWidget(parent),
ui(new Ui::formb)
{
ui->setupUi(this);
}formb::~formb()
{
delete ui;
}@
main.cpp
@
#include <QtGui/QApplication>
#include "forma.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
forma w;
#if defined(Q_WS_S60)
w.showFullScreen();
#else
w.show();
#endifreturn a.exec();
}
@
If you need any other information, i'll be glad to respond.
THanks[EDIT: fixed code formatting + list/bold; the smileys are worked on, Volker]
-
In forma.h you declare two slots:
@
private slots:
void on_formbButton_clicked();
void on_unlockButton_clicked();
@And in forma.cpp you define (the one that should open the form) with another name:
@
void forma:: on_iceButton_clicked(){
//....
}
@
Also you don't give a parent to formb (and that j pointer goes out of scope after you call the method == leak, i think i already told you that on forum.Nokia?) -
Well we can, but you won't really learn from that, i think it is more important that we explain stuff and you correct your code, do you agree with me?
So, as i said in forum.nokia, the compilation problem is not with two forms, it's all about the forma class, which has undefined slots/member functions:
I tried to explain, i will try to repeat the explanation, and please try to read and apply what we say.
So in class froma.h you declare two slots:
@private slots:
void on_formbButton_clicked(); //this one is not defined in the forma.cpp file
void on_unlockButton_clicked(); //this one is OK... it is defined in .cpp file and it close the first window
@And it forma.cpp you have the following code, that is supposed to open the second form, but this name void forma:: on_iceButton_clicked() it is not declared so the C++ compiler can't recognize it
So figure the name of the button that you want to open the second form and then use the same name for declaration and definition too.
-
formb class seems ok
So try from the Build menu: Clean All, Run qmake then Rebuild
Or manually delete the auto-generated files then rebuild.
And you can give the parent too, like this:
@
void forma:: on_ButtonName_clicked()
{
formb *j = new formb(this); //the forma will be the parent of formbj->showMaximized();
}
@ -
you know funny thing is i've tried that parenting suggestion you justst gav, but it gave same error. I'll try the build thing again when i get home.
Or maybe just reinstall qt. I the vode is seemingly ok.
But that will be when i get home. I'm currently in transit from school. -
You don't need to reinstall Qt, that won't solve the problem
Also the parent isn't a solution for this compile errorIf you give a parent you will also need to tell Qt that you want formb to be a new window, this is because your formb inherits from QWidget and not from QMainWindow or QDialog.
So complete code for slot is:
@
void forma:: on_ButtonName_clicked()
{
formb *j = new formb(this);
j->setWindowFlags(Qt::Window); //this way you show your QWidget as a new window and pass a parentj->showMaximized();
}
@
Put something inside formb and see without that line where it will appear -
Same problem here. Simulator build/run ok and Device build not.
@
void MainWindow::on_actionAbout_triggered()
{
DialogAbout about(this);
about.exec();
}
@My .pro:
@
#-------------------------------------------------Project created by QtCreator 2011-02-07T21:00:21
#-------------------------------------------------
QT += core gui
TARGET = QTBible
TEMPLATE = appSOURCES += main.cpp dialogabout.cpp mainwindow.cpp
HEADERS += dialogabout.h
mainwindow.hFORMS += dialogabout.ui
mainwindow.uiOTHER_FILES +=
Welcome.html
Notes.txtRESOURCES +=
resources.qrc@
-
ifewalter,
I was searching into log to discover some issue and found this:
@Configuration unchanged, skipping qmake step.@
I don't know why, but my dialog was not included in Makefile, because qmake creates the makefile, and it is not running!!!!
Solution: manual delete the Makefile (in your project dir). Doing a rebuild..... Voi lá.
-
Gerof,
I've create a application, add a Dialog and write a code to show the dialog. Simple.
Compiling for simulator ok, but for device gives me an error (the same problem of first post):@
/NokiaQtSDK/Symbian/SDK/EPOC32/BUILD/Quati/develop/Nokia/QTBible/QTBIBLE_0XE3918DBB/GCCE/UDEB/mainwindow.o: In function `MainWindow::on_actionAbout_triggered()':/Quati/develop/Nokia/QTBible/mainwindow.cpp:91: undefined reference to `DialogAbout::DialogAbout(QWidget*)'
/Quati/develop/Nokia/QTBible/mainwindow.cpp:95: undefined reference to `DialogAbout::~DialogAbout()'
/Quati/develop/Nokia/QTBible/mainwindow.cpp:95: undefined reference to `DialogAbout::~DialogAbout()'
make[2]: *** [\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\QTBible.exe] Error 1
make[1]: *** [TARGETQTBIBLE_0XE3918DBB] Error 2
make[1]: Leaving directory `C:/Quati/develop/Nokia/QTBible'
@I don't know what cause this. But Volker writes a clue:
[quote author="Volker" date="1296165540"]Are formb.h and formb.cpp added to your project file?
The error message
bq. undeclared reference formB::formB(QWidget*).
leads me to the guess that formb.cpp is not compiled at all.
You can post your .pro file, we can check.[/quote]
He was right: my dialogabout class was not compiling.
I've posted my .pro, but I know that information is not sufficient to resolve my problem.
So I decided to invetigate the log to find references of my class. But the first lines of log says:@
Running build steps for project QTBible...
Configuration unchanged, skipping qmake step.
Starting: "C:/NokiaQtSDK/Symbian/SDK/epoc32/tools/make.exe" debug-gcce -w
C:\NokiaQtSDK\Symbian\SDK\epoc32\tools\make.exe: Entering directory `C:/Quati/develop/Nokia/QTBible'
.......
@