Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Add Button crashes program on start
Add Button crashes program on start [message #54839] Sun, 20 September 2020 22:48 Go to next message
jimlef is currently offline  jimlef
Messages: 80
Registered: September 2020
Location: US
Member
I have the following code:
invoices.lay:
LAYOUT(CustomersWindowLayout, 1112, 476)
	ITEM(SqlArray, CustArray, SetFrame(ThinInsetFrame()).LeftPosZ(436, 656).TopPosZ(28, 420))
        .
        .
        .
	ITEM(Button, btnAddCustomer, SetLabel(t_("Add")).SetFont(SansSerifZ(16)).SetFrame(ButtonFrame()).LeftPosZ(24, 88).TopPosZ(352, 28))
END_LAYOUT

customers.cpp:
CustomersWindow::CustomersWindow() {
	String DBFile;
	String configfile = ConfigFile();
	CtrlLayout(*this, "Customers");
	
	btnAddCustomer <<= THISBACK(btnAddCustomerClick); // <-- only line added in this function since last successful run
	
... 

void CustomersWindow::btnAddCustomerClick()
{
	PromptOK("Click Add");
	return;
}

customers.h:
struct CustomersWindow : WithCustomersWindowLayout<TopWindow>
{
	String GetOutputDirectory();
	String SelectDB();
	
	String	DBFile;
	String OutputDirectory;
	String configfile = ConfigFile();
	String cfg;

	FileSel selectdbwin;
	FileSel selectodirwin;
	
public:
	typedef CustomersWindow CLASSNAME;
	CustomersWindow();
	void btnAddCustomerClick();
	void Paint ( Draw& w )
	{
		w.DrawRect ( GetSize(), Color ( 204, 255, 255 ) ); // <= enter your background color here
	}

	
};



Every time I try to run this, I get:

index.php?t=getfile&id=6207&private=0

The only change is adding this callback function in the places shown.
I can't find a thing wrong with the code, any suggestions?

Running current stable release (14429) installed from dpkg on Linux Mint (2020).

Thank you!
  • Attachment: crash.png
    (Size: 4.17KB, Downloaded 184 times)

[Updated on: Sun, 20 September 2020 22:49]

Report message to a moderator

Re: Add Button crashes program on start [message #54840 is a reply to message #54839] Sun, 20 September 2020 22:52 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 80
Registered: September 2020
Location: US
Member
By commenting out:
// btnAddCustomer <<= THISBACK(btnAddCustomerClick);
	

I eliminate the crash btw...
Re: Add Button crashes program on start [message #54842 is a reply to message #54840] Sun, 20 September 2020 23:48 Go to previous messageGo to next message
Klugier is currently online  Klugier
Messages: 932
Registered: September 2012
Location: Poland, Kraków
Experienced Contributor
Hello Jim,

I can not reproduce this on the latest nightly build. Could you try to test with nightly? You can download it from our download page. On the other hand it might be due to some other code that we are not aware at this moment.

Here is my example:
// main.cpp
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Gui16/dlg.lay>
#include <CtrlCore/lay.h>

struct MyApp : public WithDlgLayout<TopWindow> {
	MyApp() {
		CtrlLayout(*this, "MyDialog");
		
		btn << [=] { onClick(); };
	}
	
	virtual void Paint(Draw& w) override {
		w.DrawRect(GetSize(), Color(204, 255, 255));
	}
	
	void onClick() {
		PromptOK("Click Add");
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}

// dlg.lay
LAYOUT(DlgLayout, 208, 64)
	ITEM(Label, dv___0, SetLabel(t_("Label")).LeftPosZ(8, 36).TopPosZ(8, 19))
	ITEM(EditString, text, LeftPosZ(48, 92).TopPosZ(8, 19))
	ITEM(Option, option, SetLabel(t_("Option")).LeftPosZ(8, 108).TopPosZ(32, 15))
	ITEM(Button, btn, SetLabel(t_("asdasd")).SetFrame(ButtonFrame()).LeftPosZ(124, 56).TopPosZ(40, 15))
END_LAYOUT


Some code improvements you could apply:
virtual void Paint(Draw& w) override // virtual override is a nice addition - this will check that you indeed overriding this method
{
    w.DrawRect(GetSize(), Color ( 204, 255, 255 )); // <= enter your background color here
}

btnAddCustomer << [=] { btnAddCustomerClick(); }; // THISBACK is not needed in c++11 world and could be replaced with lambda.


I saw your second post. You eliminated crash by not connecting callback - this is not the solution Smile

Klugier


Ultimate++ - one framework to rule them all.

[Updated on: Sun, 20 September 2020 23:55]

Report message to a moderator

Re: Add Button crashes program on start [message #54843 is a reply to message #54842] Mon, 21 September 2020 01:07 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 80
Registered: September 2020
Location: US
Member
I tried the 15100 nightly as you suggest, it doesn't successfully compile my code, showing an error of:
/home/james/upp/uppsrc/Core/Fn.h (129): error: no viable overloaded '=' .
Very strange, as I compiled and ran your sample without a problem on both the stable and nightly versions.

So, I commented out the sql code that follows, and suddenly all compiled and ran. I added lines back in one or a few at a time, and now with none of the code commented out, it compiles and runs.

Thank you for your help with the language, I'm new at that obviously LOL but now it's working, on the stable build. Going to stub out the rest and see what happens.
Re: Add Button crashes program on start [message #54844 is a reply to message #54839] Mon, 21 September 2020 02:04 Go to previous message
jimlef is currently offline  jimlef
Messages: 80
Registered: September 2020
Location: US
Member
And here's the fully "stubbed out" working code:

#include "Invoices.h"
#include "customers.h"

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#include "Sql/sch_source.h"


CustomersWindow::CustomersWindow() {
	String DBFile;
	String configfile = ConfigFile();
	CtrlLayout(*this, "Customers");
	btnAddCustomer << [=] { btnAddCustomerClick(); }; // THISBACK is not needed in c++11 world and could be replaced with lambda.
	btnSearchCustomer << [=] { btnSearchCustomerClick(); }; // THISBACK is not needed in c++11 world and could be replaced with lambda.
	btnUpdateCustomer << [=] { btnUpdateCustomerClick(); }; // THISBACK is not needed in c++11 world and could be replaced with lambda.
	if(FileExists(configfile))
	{
        VectorMap<String, String> cfg = LoadIniFile(configfile);
        DBFile = cfg.Get("DBFile", Null);
	}
	else {
		DBFile = SelectDB();
	}
	SQL;
	Sqlite3Session sqlite3;
	if(!sqlite3.Open(DBFile)) {
		Exclamation("Can't create or open database file\n");
		return;
	}
	SQL = sqlite3;
	SqlId Customers("Customers"), id("id"), name("name"), email("email"), contact("contact"), address("address"), city("city"), state("state"), zip("zip"), taxable("taxable");
	
	CustArray.SetTable(Customers);
		
	CustArray.AddKey(id);
	// CustArray.Join(BOOK_ID, book); // joins id from other db to this id
	CustArray.AddColumn(name, "Name"); // .SetConvert(DateIntConvert());
	CustArray.AddColumn(email, "Email"); // .SetConvert(DateIntConvert());
	CustArray.AddColumn(contact, "Phone");
	CustArray.AddColumn(address, "Address");
	CustArray.AddColumn(city, "City");
	CustArray.AddColumn(state, "State");
	CustArray.AddColumn(zip, "Zip");
	CustArray.AddColumn(taxable, "Taxable?");
	CustArray.ColumnWidths("40 40 20 50 20 15 10 5");
	CustArray.SetOrderBy(id);
	
	Sql sql(sqlite3);
	sql.Execute("select * from Customers");
	

	while(sql.Fetch())
		CustArray.Add(sql);
	// CustArray.WhenBar
	CustArray.WhenLeftDouble = [=] { EditRow(); };
	
	CustArray.GoEndPostQuery();
}

void CustomersWindow::btnAddCustomerClick()
{

	PromptOK(__func__);
}

void CustomersWindow::btnUpdateCustomerClick()
{
	PromptOK(__func__);
}

void CustomersWindow::btnSearchCustomerClick()
{
	PromptOK(__func__);
}

void CustomersWindow::EditRow()
{
	PromptOK(__func__);
}

String CustomersWindow::SelectDB()
{
	selectdbwin.Type(t_("Invoices DB"), "*.jts");
	if(!selectdbwin.ExecuteOpen(t_("Select DB File")))
	{
        return "";
	}
	/*
	from http://leonardoce.interfree.it/leowiki.html "simple configfile"
	*/
	cfg << "DBFile=" << selectdbwin.Get() << "\n";
	if(!SaveFile(ConfigFile(), cfg))
	{
    	Exclamation("Error saving configuration!");
	}
	return selectdbwin.Get();
}
Previous Topic: Background color of StaticText or EditString
Next Topic: LabelBase vertical alignment
Goto Forum:
  


Current Time: Thu May 26 11:09:36 CEST 2022

Total time taken to generate the page: 0.03329 seconds