Unsolved QMessageBox showing "Loading...."
-
@Venkatesh-V said in Qmessagebox showing "Loading....":
ApplicationModal
I tried ApplicationModal, NonModal and WindowModal...nok!
I have no blocked anything because this is the beginning of my aplication....
1)read user/password (first screen)
2)read third party library and open main screen. (2nd screen)This messagebox is inside of the main screen constructor.
LerModos -> function read sqltable
...
carregarDarumaFramework -> load a huge third party librarytks
-
@Guapo
I could be way, way out on this... but I still suspect painting/event loop...
You're halfway thru constructing a "man screen" (QMainWindow
?) when you decide to put up a message box...
Temporarily, why don't you move the message box later, after the main screen has been constructed and shown, and then see? At least that will eliminate stylesheets etc. -
To complement what @JNBarchan suggests, you should likely move the library loading part outside the constructor of your MainWidget since it's not related to the contraction of that widget.
Basically, create your gui elements and once that's done, trigger the loading/setup of whatever is needed.
-
I did make some changes...
The first action of my app is ask for user/pass to login on.
There is a "Login" button to check these credencials.
After check user and pass I put this library load and my &$&#$%%@# QMessagebox.
When this load finish, I call the Principal class ( that shows the main screen ).
The old code had this Principal class constructor to load this library.
Now I´m loading this library out of any constructor and the results are exactly I the same.
-
@Guapo
But are you calling the Message Box creation after you have entered the main Qt event loop (likeapp.exec_()
) which has allowed the main window to finish drawing correctly? Or, possibly, very early, before you have started creating yourQMainWindow
? Or, what's this "third-party library" you're talking about, could that be interfering, why can't you eliminate that and see if it's relevant?It's up to you whether you want to try these things. But if you don't, I could be wrong but it seems to me nobody here is going to have a solution for you....
-
@JNBarchan
The Login Class is my QMainWindow.
int main(int argc, char *argv[]) { QApplication a(argc, argv); Login w; w.show(); return a.exec(); } ........ Login::Login(QWidget *parent) : QMainWindow(parent), ui(new Ui::Login) { ui->setupUi(this); path_images=QString("%1/images/").arg(QDir::currentPath()); QPixmap pix(QString("%1%2").arg(path_images,"selo_sabordelivery.png")); // QPixmap pix("/mnt/midia4/prj/qt/sql/sql_app/selo_sabordelivery.png"); ui->label_pic->setPixmap(pix); if(!connOpen()) ui->label_db->setText("Falha ao conectar DataBase"); else ui->label_db->setText("DataBase Conectado..."); }
and I´m loading my library (.so) inside this class...This class has a GUI.
I put this message before loading library and didn´t show anything....I´m trying to understand what is going on.
tks
-
-
connOpen only it´s makes a MySql conection
bool connOpen(){
lerconf(); // read text file mydb=QSqlDatabase::addDatabase("QMYSQL"); mydb.setDatabaseName("controle_restaurante"); mydb.setHostName(database_nome); mydb.setPort(database_port.toInt()); mydb.setUserName(database_user); mydb.setPassword(database_senha); if(!mydb.open()){ qDebug() << "Falha ao conectar ao DataBase" << mydb.lastError().text(); return false; } else{ qDebug() << ("Conectado..."); return true; } }
-
Do you mean you want to have some sort of splash screen while that library is being loaded ?
Out of curiosity, why do you need to load it by hand ?
-
This is for restaurant app. Here in Brazil, all restaurants needs a device called SAT, connected to USB and the internet (to send all sales data to our beloved government) :). This device has its own library to create a sale invoice and send all data to government.
Load by hand is the way used to access the internal functions.
I don´t know another way to acess internal function from a .dll or .so .
My intention is open a screen to warning loading, because the user could think software is crashed. This library takes a several seconds to load. -
@Guapo said in Qmessagebox showing "Loading....":
I don´t know another way to acess internal function from a .dll or .so
Usually you link your app against a library to use it.
See http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html -
when I tried to use this library, my first option was
at my .pro fileLIBS += -L"/mnt/midia4/prj/qt/Controle" -lDarumaFramework
But I cannot exec the internal function ( ex: rVerificarComunicacao_SAT_Daruma() ).
So, I received from the library owner a file to load it´s library and execute internal functions;
bibliotecaDinamica = dlopen("./libDarumaFramework.so", RTLD_NOW);
This is working!
Today, I tried to include this line at my .pro file
LIBS += -L"/mnt/midia4/prj/qt/Controle" -lDarumaFramework -ldl
The library loading is during the aplication load....I can exec the internal function.
But this is all inside the Qt Creator....when I tried to exec my aplication from the CL, there is a segmentation fault.
I need more information, but this note is only to update you that I´m studying your hint.tks
-
@Guapo said in Qmessagebox showing "Loading....":
bibliotecaDinamica = dlopen("./libDarumaFramework.so", RTLD_NOW);
But this is all inside the Qt Creator....when I tried to exec my aplication from the CL, there is a segmentation fault.
-
You need to check the return result of
dlopen
, as it may fail? Do you proceed to usebibliotecaDinamica
without verifying its value? -
./libDarumaFramework.so
is a relative path; it must be found in the current directory. Is your current directory right for this while running from QtCreator, but something else when run from the command line? (I don't know whatdlopen
's behaviour is exactly, but you might be better with plainlibDarumaFramework.so
without the leading./
.) Have you put the library in the same directory as your executable, alongLD_LIBRARY_PATH
, or what?
-
-
@JNBarchan
Yes...my library is on the same directory as my executable.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);qDebug()<< "inicio"; Login w; w.show(); return a.exec();
}
The segmentation fault occours before "inicio". (only executing in CL at the directory where are all files....this code is ok executing inside the Qt Creator ).
-
@Guapo If you want to execute your app outside of QtCreator you need to deploy it.
See http://doc.qt.io/qt-5/deployment.html -
I´m trying do execute my aplication only for tests. I´m executing it at the same folder as compiled.
When I do not use this line:
LIBS += -L"/mnt/midia4/prj/qt/Controle" -lDarumaFramework -ldl
It is possible execute it from CL.
When I need to make deployment, I´ve used linuxdeployqt script.
-
@Guapo You can set LD_LIBRARY_PATH to point to the directory where this lib is and then start your app, see http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
-
@jsulm excuse me for this delay.
I found a performance problem and I need to fix it before.
I don´t know if it´s better open a new point to discuss.
This code has an answer in 1sec. This exec a function "EnviarDadosVenda" from my external lib.
#include <dlfcn.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <inttypes.h> #include <time.h> #include "helpers.c" int main(int argc, char *argv[]) { char * (*_EnviarDadosVenda) (int, char *, char *); void * handle; char * error; char * resposta; char cXML[5000]; strcpy(cXML, "this is for XML"); handle = dlopen ("./libsat.so", RTLD_LAZY); _EnviarDadosVenda = dlsym(handle, "EnviarDadosVenda"); typedef char* (*funcao)(int, char*, char*); funcao runGui = (funcao)dlsym(handle, "EnviarDadosVenda"); resposta = runGui(_sessao(),"12345678", cXML); // 1sec to return data printf("======================================================\n"); printf("\nExecutando funcao: _EnviarDadosVenda2\n"); printf("\nRetorno: %s\n\n", (char *) resposta); printf("==++==================================================\n"); }
This function, running in qt, runs the same code in 16 secs. It´s the same function and the same lib.
char * EnviarDadosVenda2_libsat(int numerossessao, QString codigoativacao, QString pszXML){ char * resposta; char cXML[1100]; QDateTime agora=QDateTime::currentDateTime(); char* _EnviarDadosVenda(int , char*, char*); strcpy(cXML, "My XML data"); void* handle = dlopen("./libsat.so", RTLD_LAZY); typedef char* (*funcao)(int, char*, char*); funcao runGui = (funcao)dlsym(handle, "EnviarDadosVenda"); qDebug() << "Vai executar EnviarDadosVenda2_libsat"; resposta = runGui(numerossessao,"12345678", cXML); // 16 seconds to return data qDebug() << "saiu EnviarDadosVenda2_libsat " << QDateTime::currentDateTime().toTime_t()-agora.toTime_t(); return resposta; }
-
@Guapo Well, I don't know why this difference. Are you sure you pass exactly the same data to EnviarDadosVenda in both cases?
Also you wrote runGui takes 16 seconds to execute, but actually you measure time for copying the data, loading the library and resolving the symbol as well. Loading a library and resolving symbols can take some time, moveQDateTime agora=QDateTime::currentDateTime();
just before you call runGui.
-
@jsulm yes...I´m sure the input data are the same at the both cases.
This xml string has more than 1000 bytes.
I made another test using this same function in a exclusive qt project that contain only this function and this function delay 1sec.
There is something in my project that retards the execution.