ورود

View Full Version : مبتدی: این خطا یعنی چی؟ ‎"Folan" in namespace Ui doesnot name of type



iambehnam
شنبه 01 تیر 1392, 16:57 عصر
:اشتباه: سلام بر همه :اشتباه:
من دو تا فرم ساده برای دو برنامه ایجاد کردم و اونا را به برنامه‌هام اضافه کردم تا در هدر کلاس اصلیم از اون‌ها استفاده کنم#include "ui_Folan.h"
...
class Folan:
{
...
private:
Ui::Folan ui;
} و در هردو با خطایی که در بالا گفتم روبرو شدم، با اینکه برنامه‌ها کاملا متفاوتند و فرم‌ها هم همینطور.
به نظرتون چنین خطایی برای چیه؟

در ضمن من مبتدیم :خجالت: و برنامه از کتاب کپی شده پس نکته‌ی خاصی در کار نیست و راحت می‌تونید جوابم را بدید.
منتظر و ممنونم دوستان

rubiks.kde
یک شنبه 02 تیر 1392, 00:12 صبح
دوست عزیز به این لینک (http://www.qtforum.org/article/26052/a-really-novice-problem-that-i-don-t-understand.html) مراجعه کن اگه مشکلت حل نشد کد رو به صورت کامل بزار تا بررسی کنیم

iambehnam
یک شنبه 02 تیر 1392, 12:50 عصر
ممنون ولی لینک مشکل داشت.// byteConverter/ByteConverterDialog.h
#ifndef BYTECONVERTERDIALOG_H
#define BYTECONVERTERDIALOG_H
#include <QDialog>
#include "ui_byteconverterdialog.h"
class QLineEdit;

class ByteConverterDialog : public QDialog
{
Q_OBJECT
Ui::ByteConverterDialog ui;
public:
ByteConverterDialog();
private slots:
void decChanged(const QString&);
void hexChanged(const QString&);
void binChanged(const QString&);
};
#endif

و اینم سی پی پیش// byteConverter/ByteConverterDialog.cpp
#include "byteconverterdialog.h"
#include <QValidator>


ByteConverterDialog::ByteConverterDialog(QWidget *parent) : QDialog(parent)
{
// Limit input to valid values
QIntValidator* decValidator = new QIntValidator(0, 255, decEdit);
decEdit->setValidator(decValidator);
QRegExpValidator* hexValidator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,2}"), hexEdit);
hexEdit->setValidator(hexValidator);
QRegExpValidator* binValidator = new QRegExpValidator(QRegExp("[01]{1,8}"), binEdit);
binEdit->setValidator(binValidator);

ui.setupUi(this);
connect(ui.decEdit, SIGNAL(textChanged(const QString&)), this, SLOT(decChanged(const QString&)));
connect(ui.hexEdit, SIGNAL(textChanged(const QString&)), this, SLOT(hexChanged(const QString&)));
connect(ui.binEdit, SIGNAL(textChanged(const QString&)), this, SLOT(binChanged(const QString&)));
}


void ByteConverterDialog::decChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok);
if (ok) {
ui.hexEdit->setText(QString::number(num, 16));
ui.binEdit->setText(QString::number(num, 2));
} else {
ui.hexEdit->setText("");
ui.binEdit->setText("");
}
}


void ByteConverterDialog::hexChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok, 16);
if (ok) {
ui.decEdit->setText(QString::number(num));
ui.binEdit->setText(QString::number(num, 2));
} else {
ui.decEdit->setText("");
ui.binEdit->setText("");
}
}


void ByteConverterDialog::binChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok, 2);
if (ok) {
ui.decEdit->setText(QString::number(num));
ui.hexEdit->setText(QString::number(num, 16));
} else {
ui.decEdit->setText("");
ui.hexEdit->setText("");
}
}

و اینم فرمش<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>ByteConverterDialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="decLabel">
<property name="text">
<string>&amp;Decimal</string>
</property>
<property name="buddy">
<cstring>decEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="decEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="hexLabel">
<property name="text">
<string>&amp;Hex</string>
</property>
<property name="buddy">
<cstring>hexEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="hexEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="binLabel">
<property name="text">
<string>&amp;Binary</string>
</property>
<property name="buddy">
<cstring>binEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="binEdit"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>308</width>
<height>147</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>380</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="exitButton">
<property name="text">
<string>&amp;Quit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>exitButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>314</x>
<y>272</y>
</hint>
<hint type="destinationlabel">
<x>389</x>
<y>211</y>
</hint>
</hints>
</connection>
</connections>
</ui>

ببخشید طولانی شد

iambehnam
جمعه 07 تیر 1392, 12:31 عصر
سلام دوباره. خوب از یه مبتدی انتظار بیشتر نداشته باشید::قهقهه:

جواب:
به این قسمت فرم دقت کنید:<widget class="QDialog" name="Dialog">که البته در designer هم هست و میتونید تغییر نامش بدید . منظورم اینه که نام اصلی ویجت Dialog هست و در هدرفایل بایدUi::ByteConverterDialog ui;بهUi::Dialog ui;تغییر کند.
بقیه کد را هم بیخیال

موفق باشید

حامد مصافی
جمعه 07 تیر 1392, 12:35 عصر
فایل‌های شما رو به این صورت ویرایش کردم:

فایل cpp
// byteConverter/ByteConverterDialog.cpp
#include "byteconverterdialog.h"
#include <QValidator>


ByteConverterDialog::ByteConverterDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ByteConverterDialog)
{
ui->setupUi(this);
// Limit input to valid values
QIntValidator* decValidator = new QIntValidator(0, 255, ui->decEdit);
ui->decEdit->setValidator(decValidator);
QRegExpValidator* hexValidator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,2}"), ui->hexEdit);
ui->hexEdit->setValidator(hexValidator);
QRegExpValidator* binValidator = new QRegExpValidator(QRegExp("[01]{1,8}"), ui->binEdit);
ui->binEdit->setValidator(binValidator);

connect(ui->decEdit, SIGNAL(textChanged(const QString&)), this, SLOT(decChanged(const QString&)));
connect(ui->hexEdit, SIGNAL(textChanged(const QString&)), this, SLOT(hexChanged(const QString&)));
connect(ui->binEdit, SIGNAL(textChanged(const QString&)), this, SLOT(binChanged(const QString&)));
}


void ByteConverterDialog::decChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok);
if (ok) {
ui->hexEdit->setText(QString::number(num, 16));
ui->binEdit->setText(QString::number(num, 2));
} else {
ui->hexEdit->setText("");
ui->binEdit->setText("");
}
}


void ByteConverterDialog::hexChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok, 16);
if (ok) {
ui->decEdit->setText(QString::number(num));
ui->binEdit->setText(QString::number(num, 2));
} else {
ui->decEdit->setText("");
ui->binEdit->setText("");
}
}


void ByteConverterDialog::binChanged(const QString& newValue)
{
bool ok;
int num = newValue.toInt(&ok, 2);
if (ok) {
ui->decEdit->setText(QString::number(num));
ui->hexEdit->setText(QString::number(num, 16));
} else {
ui->decEdit->setText("");
ui->hexEdit->setText("");
}
}


فایل h
// byteConverter/ByteConverterDialog.h
#ifndef BYTECONVERTERDIALOG_H
#define BYTECONVERTERDIALOG_H
#include <QDialog>
#include "ui_byteconverterdialog.h"
class QLineEdit;

namespace Ui {
class ByteConverterDialog;
}

class ByteConverterDialog : public QDialog
{
Q_OBJECT
Ui::ByteConverterDialog *ui;

public:
ByteConverterDialog(QWidget *parent = 0);

private slots:
void decChanged(const QString&);
void hexChanged(const QString&);
void binChanged(const QString&);
};
#endif


فایل ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ByteConverterDialog</class>
<widget class="QDialog" name="ByteConverterDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>ByteConverterDialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="decLabel">
<property name="text">
<string>&amp;Decimal</string>
</property>
<property name="buddy">
<cstring>decEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="decEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="hexLabel">
<property name="text">
<string>&amp;Hex</string>
</property>
<property name="buddy">
<cstring>hexEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="hexEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="binLabel">
<property name="text">
<string>&amp;Binary</string>
</property>
<property name="buddy">
<cstring>binEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="binEdit"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>308</width>
<height>147</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>380</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="exitButton">
<property name="text">
<string>&amp;Quit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>exitButton</sender>
<signal>clicked()</signal>
<receiver>ByteConverterDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>314</x>
<y>272</y>
</hint>
<hint type="destinationlabel">
<x>389</x>
<y>211</y>
</hint>
</hints>
</connection>
</connections>
</ui>