Solved Signal no being emitted from within slot
-
DbHandler calls bool OrderHandler::receiveOrder(Order *order) . Yes that'st the flow, you got it.
DbHandler emits pendingOrder(Order *), OrderHandler receives the signal from DbHandler and emits newOrderAvailable(Order *) signal to MainWin::addOrder(Order *);
connect(dbhandler, &DbHandler::pendingOrders, this, &OrderHandler::receiveOrder, Qt::DirectConnection);
bool DbHandler::loadPendingOrders() { QSqlQuery orderQuery, itemQuery; // 10 == NOT_COLLECTED orderQuery.prepare("SELECT * from order_info WHERE delivery_status=10"); if(!orderQuery.exec()) { qDebug() << orderQuery.lastError(); return false; } int id = orderQuery.record().indexOf("id"); int client_name = orderQuery.record().indexOf("client_name"); int cpf = orderQuery.record().indexOf("cpf"); int n_uniq_itens = orderQuery.record().indexOf("n_uniq_itens"); int pag_status = orderQuery.record().indexOf("pag_status"); int prod_status = orderQuery.record().indexOf("prod_status"); int term_status = orderQuery.record().indexOf("term_status"); int delivery_status = orderQuery.record().indexOf("delivery_status"); while (orderQuery.next()) { Order *order = new Order(this); order->id = orderQuery.value(id).toUInt(); order->client_name = orderQuery.value(client_name).toString(); order->cpf = orderQuery.value(cpf).toString(); order->payment_status = orderQuery.value(pag_status).toUInt(); order->n_uniq_item = orderQuery.value(n_uniq_itens).toUInt(); order->prod_status = orderQuery.value(prod_status).toUInt(); order->term_status = orderQuery.value(term_status).toUInt(); order->delivery_status = orderQuery.value(delivery_status).toUInt(); //qDebug() << "Load order from database: " << pendingOrder->id; //qDebug() << pendingOrder; emit pendingOrders(order); } return true; }
-
Hi
There must be something we are missing in regards to emit from a slot while
a signal is in progress. ( i have not had this situation and it seems perfectly normal)I should be able to reproduce it if have
a mainwindow and some widget i use for floating window
that i show using ->show()
in constructor (of floating window) i emit test("hello");and in the floating window i have a button and in its clicked, i also
emit test("hello 2");Mainwindow should not get "hello 2" if something up.
Does that sounds like same usage as you ?
-
Yes, looks like a similar case.
Can I post my code somewhere? This way would be easier to debug or even see if the code has an explict error I'm not spotting. -
@Gabriel-Duarte
Ok. super. I must do some shopping then i will try.
You can use use google drive/dropbox and post link here (with zip file) or
use https://www.filemail.com/
( you dont have to use real email adresses. just grab the URL in last page)
and post url here. ( it expires in 6 days)Update:
Tried a mock up example but in both cases it was emitted.The full source and data files would really help to spot it.
-
Hi
I asked for help/input and was suggested
"my best guess is his DbHandler::loadPendingOrders simply is not called. make him break at the OrderHandler::receiveOrder at the qDebug statement and to pull the stack trace."Thats a good plan.
Also full source code could also help to find out
what goes wrong.
It should work as far as i can see and understand from your code and
explanations of the setup. -
@mrjj REALLY thanks for your attention!
You will post the source code.DbHandler::loadPendingOrders is being called, for sure, because my list of Orders is being increased and if I call qDebug() << "something" inside it, I can see some output coming from there but emit newOrderAvailable().
emit pendingOrders(order) is being emitted from the method DbHandler:loadPendingOrders() at each order it gets from database.
DbHandler->loadePendingOrders() is begin called inside OrderHandler constructor right after this:
connect(dbhandler, &DbHandler::pendingOrders, this, &OrderHandler::receiveOrder, Qt::DirectConnection); dbhandler->loadPendingOrders();
-
-
Hi
Found it. ( i think) Logical error :)
Would not have seen it without full code.
In
OrderHandler::OrderHandler(QObject *parent) : QObject(parent) {
you hook up
connect(dbhandler, &DbHandler::pendingOrders, this, &OrderHandler::receiveOrder, Qt::DirectConnection);
// and call it
dbhandler->loadPendingOrders();But since its inside the constructor of orderHandler,
MainWin::MainWin(QWidget *parent) :
{
order_handler = new OrderHandler(this);// << loadPendingOrders() called here
connect(order_handler, &OrderHandler::newOrderAvailable, this, &MainWin::addOrder); // but signal first hooked up here !so that is why nothing seems to happen.
-
@mrjj THANK YOU SO MUCH!
Dumb logical error, thanks a lot for helping me out, for your attention and patience!
-
@Gabriel-Duarte
Well it was a sneaky one and easy to make.
In fact, i mention as test case to emit in constructor and that
would been same mistake.
And you are welcome. happy saturday.