Note: The question from http://www.qtcentre.org/threads/31327-QFormBuilder-save-BAD-
I create in QtDesigner standart QWidget and add standart widgets (QPushButtons, QLineEdit and etc.)
Then save it to "formIn.ui" file. Next, load and save it with QFormBuilder in "formOut.ui" BUT size of dest file ("formOut.ui") more then 126kb!!!!
Scr file "formIn.ui" created with QtDesigner is 2kb only!!! Also then I open "formOut.ui" in QtDesigner it's opened incorrect!
It's trouble me! May be some people know how to solve it?
QFormBuilder fb;
QFile fileIn("c:/formIn.ui"); //file created in Qtdesigner
QFile fileOut("c:/formOut.ui");
bool isOk =false;
isOk = fileIn.open(QIODevice::ReadOnly);
isOk = fileOut.open(QIODevice::ReadWrite);
QWidget *w = fb.load(&fileIn, 0);
fb.save(&fileOut, w);
Related
I'm trying to load .obj files into Qt using the Qt3D library. So far I have this code mostly copied from one of the examples:
Qt3DCore::QEntity *createScene()
{
// Root entity
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
// Material
Qt3DRender::QMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity);
// Chest Entity
Qt3DCore::QEntity *chestEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QMesh *chestMesh = new Qt3DRender::QMesh(rootEntity);
chestMesh->setSource(QUrl("qrc:/PT18E.obj"));
chestEntity->addComponent(chestMesh);
chestEntity->addComponent(material);
return rootEntity;
}
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
Qt3DExtras::Qt3DWindow view;
Qt3DCore::QEntity *scene = createScene();
// Camera
Qt3DRender::QCamera *camera = view.camera();
camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
camera->setPosition(QVector3D(0, 0, 1));
camera->setViewCenter(QVector3D(0, 0, 0));
// For camera controls
Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(scene);
camController->setLinearSpeed( 10.0f );
camController->setLookSpeed( 180.0f );
camController->setCamera(camera);
view.setRootEntity(scene);
view.show();
return app.exec();
}
So far, the application can render the object and display it. However, I had to attach the .obj file to a qrc file in order for it to be able to find and render it. When I try to set the source for the chestMesh using the absolute path from any directory, e.g.,
chestMesh->setSource(QURL(C:/Users/username/Documents/Qt/simple-cpp/PT18E.obj))
it does not work. Nothing gets rendered and I see the error in the console saying
QFSFileEngine::open: No file name specified
I've tried adding the exact same path to a QFile object and use the exists function to see if the path is correct, and sure enough it is. But for some reason the mesh cannot use a source that isn't in a qrc file.
How can I load and render any .obj file from the file system (without having to put it in a qrc) in Qt?
For composing the correct url pointing to the file we can try static call QUrl::fromLocalFile. Or given the above code:
chestMesh->setSource(QUrl::fromLocalFile(winPath2ObjFile));
I have Qt Resource file (res.qrc) in my Qt Application. I imported my custom font in resource as below:
:/fonts/aa_marcus_east_syriac.ttf
Also i define in header file:
private:
QFont assyrianEventsAAMarcusEastSyriac;
I used QTextEdit in mainwindow. When user click on a button, my application read a text file. every row in text file should be imported in QTextEdit but some lines should be has aa_marcus_east_syriac.ttf font from my resource. So I wrote this codes:
void Widget::readMonthAssyrianEvents()
{
QStringList eventsList;
eventsList = readEventFile();
ui->notificationTextEdit->setCurrentFont(assyrianEventsAAMarcusEastSyriac);
for (int index = 0; index < eventsList.length(); index++)
{
QString eventType, eventContent;
QStringList tempStringList = eventsList[index].split('|');
eventType = tempStringList[0];
eventContent = tempStringList[1];
if (eventType == "0")
ui->notificationTextEdit->append(eventContent);
}
}
readEventFile() function works fine. It read text file and get all lines as QStringList. the "assyrianEventsAAMarcusEastSyriac" variable initialized in another function called init(). this is init() function:
int id = QFontDatabase::addApplicationFont(":/fonts/aa_marcus_east_syriac.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
assyrianEventsAAMarcusEastSyriac.setFamily(family);
assyrianEventsAAMarcusEastSyriac.setPointSize(20);
My problem is that QTextEdit doesn't change font of it's contents to my custom font.
How can I solve this problem? Please help me guys.
Thanks
I think the error is in
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
Have you checked that .at(0) is actually your custom font ?
Most likely you can solve this by calling assyrianEventsAAMarcusEastSyriac.setFamily
with an explicit string of the font family just like
assyrianEventsAAMarcusEastSyriac.setFamily("Marcus East Syriac");
If that doesn't work either, maybe your custom font is malformed or doesn't provide a font family name. Therefore I suggest you to try first with a working font and then eventually go back to custom stuff.
I made a push button that will browse and get a textfile. But I need to open it in a new window to check if the content of the textfile is correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows which file I'm looking at. In other words, the directory of the file that is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
I suggest using one of powerful text interfaces available:
void MainWindow::openfile() {
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
// show the directory path of opened file
dir->setText(QFileInfo(file1).dir().path());
QTextBrowser *b = new QTextBrowser;
b->setText(file1.readAll());
b->show();
}
dir is a member variable, initialized in constructor with
dir = new QLineEdit(this);
you should make a new window by add a Dialog or Mainwindow. after that add widgets like textEdit and other things to your new Dialog.
you need to learn some basics of Qt framework:
there is very well documentation of Qt, you can use it.
and also there is about 100 short videos of Qt learning.
I have an application that I implemented, and want to display an image in a widget, but I get an error SIGSEGV, I view it from a directory, but in reality after heave from a buffer
not what the problem is I leave my code here:
void Image:: on_pushButton_clicked ()
{
this-> conn-> connect (this-> ui-> lineEdit_2-> text (),
this-> ui-> lineEdit-> text (). Toint ()); QLayout* layout;
QString fileName = QFileDialog:: GetOpenFileName (this,
tr ("Open File"), QDir:: currentPath (),
"files (*. jpg *. png)");
QImage image (fileName);
QLabel * label = new QLabel (this);
label-> setPixmap (QPixmap:: FromImage (image));
label-> setScaledContents (true);
layout-> addWidget (label);
label-> show ();
}
I can leave if you want to help my application link for the download
thank you very much
thank you very much and I managed to see the image, I want to load from a buffer like this: QBuffer * buffer = new QBuffer (conex);
QImage * image = new QImage ();
image-> loadFromData (buffer-> buffer ());
I tried this to make my image but I get errors
QBuffer * buffer = new QBuffer (conn);
QImage image = new QImage ();
image-> loadFromData (buffer-> buffer ());
errors are as follows:
C:\ejemplos_qt\teratermobile-build-simulator..\teratermobile\imagen.cpp:81: error: conversion from 'QImage*' to non-scalar type 'QImage' requested
C:\ejemplos_qt\teratermobile-build-simulator..\teratermobile\imagen.cpp:82: error: base operand of '->' has non-pointer type 'QImage'
You didn't initialize your layout variable before using it with something like this:
layout = new QVBoxLayout(widget); // widget is where you want to put the QLabel
or you can reuse an already created layout.
If you want to show the QLabel as a top-level window, remove completely the two lines about the layout.
I'm having a bit of trouble with my function for displaying pdf's with the poppler library. The code below is the function in which the problem occurs.
const QString &file is the path to the file
int page is the page on which it has to open
When i set file to a real path (e.g. "/Users/User/Documents/xxx.pdf"), it is no problem to open it. But when i give the path to a qrc file (":/files/xxx.pdf"), it won't work. I want to use it for displaying a user manual for instance, within the application.
I've also tried first making a QFile out of it, opening it and doing readAll, then loading the QByteArray received by doingPoppler::Document::loadFromData(the qbytearray), but it errors already when opening the QFile in ReadOnly mode.
void class::setPdf(const QString &file, int page)
{
Poppler::Document *doc = Poppler::Document::load(file);
if (!doc) {
QMessageBox msgbox(QMessageBox::Critical, tr("Open Error"), tr("Please check preferences: cannot open:\n") + file,
QMessageBox::Ok, this);
msgbox.exec();
}
else{ /*Code for displaying the pdf, which works fine*/
}
}
I hope you can help me,
greetings,
Matt
I've also tried first making a QFile
out of it, opening it and doing
readAll, then loading the QByteArray
received by
doingPoppler::Document::loadFromData(the
qbytearray), but it errors already
when opening the QFile in ReadOnly
mode.
QFile f;
f.setFileName(":/skin/AppIcon16.png");
f.open(QIODevice::ReadOnly);
QByteArray r=f.readAll();
Perfectly reads all data from the resource, have checked it. So i suggest you did something wrong when tried that. Maybe path errors, maybe something else...