Cannot open include file " but I can create objects "
-
oh yeah forgot about qwidget in the implement :D
-
Still same problem :(
-
the code " I changed the project to solve the first problem so I named the class to another name "
imp:
@
#include "checkclass.h"checkclass::checkclass(QWidget parent):
QWidget(){
edit = new QLineEdit;
edit1=new QLineEdit;left= new QHBoxLayout; Main=new QHBoxLayout; edit->setMaximumWidth(20); edit->setFixedWidth(20); edit->setValidator(Valid); edit1->setMaximumWidth(20); edit1->setFixedWidth(20); edit1->setValidator(Valid); QObject:: connect(edit,SIGNAL(editingFinished()),this,SLOT(convert)); QObject:: connect(edit1,SIGNAL(editingFinished()),this,SLOT(convert1)); left->addWidget(edit); left->addWidget(edit1); Main->addLayout(left); setLayout(Main);
}
void checkclass::convert(){
QString numbertext=edit->text();
int x=numbertext.toInt();}
void checkclass::convert1(){
QString numbertext=edit1->text();
int y=numbertext.toInt();}
@
header:
@
#ifndef CHECKCLASS_H
#define CHECKCLASS_H
#include<QLabel>
#include<QHBoxLayout>
#include<QLineEdit>
#include<QIntValidator>
#include<QWidget>
class checkclass : public QWidget
{
public:
checkclass(QWidget parent);void convert(); void convert1(); private: QLineEdit *edit; QLineEdit *edit1; QIntValidator *Valid; QHBoxLayout *left; QHBoxLayout *Main;
};
#endif // CHECKCLASS_H
@ -
Valid is not initialized
-
same problem :(
-
@SGaist , Hopefully you didn't go to sleep yet , I really need your help , because tomorrow I want to focus on studying for my mid term exam :D
-
The problem happens only when I use show function like for example:
myclass *A;
A->show();it crashes , when I don't use show() my program runs just fine in the backround.
-
[quote author="Project try" date="1394235877"]The problem happens only when I use show function like for example:
myclass *A;
A->show();it crashes , when I don't use show() my program runs just fine in the backround.[/quote]Like SGaist said, you didn't initialize your pointer. A does not point to a valid object yet, so it will cause problems if you try to use it. It's not just show(), ANY function can cause a crash -- it might not crash immediately, but will crash some time later.
Call new to initialize your pointer. This is a very fundamental (and very important) concept of C++ by the way; if you are not familiar with it, I highly recommend reading a tutorial about pointers.
-
Thanks man ^^ , it worked
but can you please tell me why did we put : QWidget *parent in the arguments of the constructor ? even though we didn't send any argument but it was a default so what's the point ?
and since it didn't take any argument there's no need to delete that parent pointer ? , because I saw a lot of examples and most of them use it like I said but they didn't really explain why.
-
Good night , I need to sleep , thanks guys for helping me , and sorry for asking lots of question :(
-
So that you can reuse your widget the same way you would a standard Qt widget.
Even if you don't reuse it somewhere else, it's good practice to keep a consistent code base. You never know who will use your code later
-
Parent-child relationships have multiple uses in Qt. One of them is memory management. When a parent object is deleted, it will automatically delete its child objects. Thus, you should never store or delete the parent pointer.
[quote]
@
checkclass::checkclass(QWidget parent):
QWidget(){
...
@
[/quote]You have not made use of the parent pointer. Pass it to the QWidget constructor, and let Qt take care of things in the background:@
checkclass::checkclass(QWidget parent):
QWidget(parent){
...
@