PDA

View Full Version : Newbie with an instant question on how to open a second form..



microbrain
1st April 2010, 23:14
Hi,

Microbrain here, trying to move to QT from visual basic since I am told I can make apps for windows and linux all in the same language.
but what a struggle! - Anyway I need to know if there is a simple command to open a second (different) form from the first one.

thnx.

wysota
1st April 2010, 23:31
http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms

squidge
1st April 2010, 23:34
What kind of form? A dialog? Some other QWidget derived object?

Try exec() or show()

microbrain
4th April 2010, 18:57
OK,

I managed to sort that one out eventually, but can anybody tell me whether it's possible to write c programs on qt4 ? c++ is nothing more than an unneccessary layer of crap added to what was once a pretty good language, it serves no purpose whatsoevver other than to totally confuse.

squidge
4th April 2010, 19:21
Qt in C would be a nightmare to code for and be totally confusing for both the people attempting to maintain it and the people trying to use it as a framework. Not to mention that the amount of code duplication needed would be hideous.

wysota
4th April 2010, 19:58
Qt in C would be WinAPI-- ;)

takechi
8th October 2010, 12:16
http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms

please give me a full example for this problem :( iam a newbie in QT and C++ and i don't understand it :-S
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include "form2.h"

class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
virtual ~MyWidget();
virtual void openForm2();
};

MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(200, 120);

QPushButton *quit = new QPushButton(tr("Quit"), this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold));

connect(quit, SIGNAL(clicked()), qApp, SLOT(openForm2()));
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}

void MyWidget::openForm2(){

static MyWidget *form2 = new MyWidget(this);
form2->show();
form2->activateWindow(); // or form2->setActiveWindow() in Qt3
form2->raise();
}
i had 2 form in this : form1.ui and form2.ui
i use QT4

Thanks

marcvanriet
8th October 2010, 14:07
Hi,

Please see the thread More than one forms (http://www.qtcentre.org/threads/34114-More-than-one-forms?highlight=more+than+one+forms). One of the replies has an attachment with an example project.

If you don't know C++ when you start to use Qt, you won't get very far. Get yourself a good book. C++ is not just some crap ontop C. It brings object oriented programming into C. Object oriented programming is one of the fundamental characteristics of many programming languagues today, even of many scripting languages.

Regards,
Marc